/*
 * Layout system.
 *
 * Loaded after theme.css. theme.css owns colour, type and components; this
 * file owns where things sit: one page measure, a page header, vertical rhythm
 * on the 4px grid, and the few grids the pages share.
 *
 *   .ds-page            fluid content column (dashboards, lists, forms)
 *   .ds-page--wide      full width (wide data tables only)
 *   .ds-page-head       title, one-line description, actions on the right
 *   .ds-section         a block of the page, 32px apart (24 / 40 variants)
 *   .ds-stack           vertical list of blocks, 16px apart
 *   .ds-split           two columns, one under 860px
 *   .ds-form-grid       two columns of labelled fields
 *   .ds-toolbar         filters, search and actions above a table
 *   .ds-table-wrap      a table scrolls inside here, never the page
 *   .ds-stat-grid       stat / chart cards on one responsive grid
 *   .ds-measure         fluid inner block for forms above results
 *
 * The topbar and breadcrumbs of a page that uses .ds-page are inset so the
 * title starts on the same left edge as the content, at every width.
 */

:root {
    --ds-page-width: 1200px;
    --ds-narrow-width: 720px;
    --ds-gutter: 16px;
    --ds-space-1: 4px;
    --ds-space-2: 8px;
    --ds-space-3: 12px;
    --ds-space-4: 16px;
    --ds-space-6: 24px;
    --ds-space-8: 32px;
    --ds-space-10: 40px;
    --ds-space-16: 64px;
    /* Height of the fixed bottom tab bar on phones (mobile_nav). */
    --ds-mobile-bar: 64px;
}

@media (min-width: 768px) {
    :root { --ds-gutter: 24px; }
}

@media (min-width: 1024px) {
    :root { --ds-gutter: 32px; }
}

/* ---------- measure ---------- */

/* The measure of the current page. The topbar and breadcrumbs read it too. */
body { --ds-measure: 100%; }
body:has(.ds-page--narrow) { --ds-measure: 100%; }
body:has(.ds-page--wide) { --ds-measure: 100%; }

/* Left edge of the content column, relative to the column it sits in. The
   percentage resolves against whichever element uses it, which is always a
   full-width child of #content. */
body {
    --ds-inset: max(var(--ds-gutter), calc((100% - var(--ds-measure)) / 2));
}

/* Let the content column shrink below its widest table, so a table scrolls
   in its own wrapper instead of pushing the page sideways. */
#content-wrapper, #content { min-width: 0; }

.ds-page,
#content .ds-page,
#content .container-fluid.ds-page {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-inline: auto;
    padding: var(--ds-space-6) var(--ds-gutter) var(--ds-space-16);
}

.ds-page--wide { --ds-measure: 100%; }

/* Two .ds-page blocks in a row (e.g. a dashboard with a conditional second
   half) read as one page. */
#content .ds-page + .ds-page { padding-top: 0; }

/* Phones: the bottom tab bar is fixed over the page, so every page (with or
   without .ds-page) reserves its height plus the home-indicator inset. */
@media (max-width: 767.98px) {
    #wrapper #content-wrapper {
        margin-bottom: 0 !important;
        padding-bottom: calc(var(--ds-mobile-bar) + env(safe-area-inset-bottom, 0px));
    }
    .ds-page,
    #content .ds-page,
    #content .container-fluid.ds-page { padding-bottom: var(--ds-space-6); }
}

/* Prose inside cards (descriptions, how-it-works lists) keeps a readable
   line length even on a page-width page. */
.ds-page .description-list,
.ds-page .card-body > p,
.ds-page .ds-prose { max-width: 72ch; }

/* A card that only holds prose takes the prose's width rather than leaving
   an empty half beside it. */
.ds-page :is(.card, .card-style):has(> .description-list, > .card-body > .description-list) { max-width: calc(72ch + 2 * 16px); }

/* Group headings in the sidebar line up with the items under them. */
.sidebar .ds-nav-heading { text-align: left; padding-inline: 10px; }

.ds-page img, .ds-page canvas, .ds-page video { max-width: 100%; }

/* Keep run forms fluid above their results tables. */
.ds-measure {
    width: 100%;
    max-width: 100%;
    margin-inline: auto;
}

/* ---------- topbar and breadcrumbs follow the content edge ---------- */

body:has(.ds-page) .topbar,
body:has(.ds-page) nav.navbar.topbar {
    padding-left: var(--ds-inset) !important;
    padding-right: var(--ds-inset) !important;
    margin-bottom: 0 !important;
}

body:has(.ds-page) .ds-breadcrumbs {
    padding-left: var(--ds-inset);
    padding-right: var(--ds-inset);
}

/* The title in the topbar sits flush with the content, with no stray
   offsets from the old utility classes. */
body:has(.ds-page) .topbar .page-top-heading {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

body:has(.ds-page) .topbar > .navbar-nav { min-width: 0; }
body:has(.ds-page) .topbar .page-top-heading h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- page head ---------- */

.ds-page-head,
.ds-page > .page-top-heading {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-3) var(--ds-space-4);
    margin: 0 0 var(--ds-space-6) !important;
    padding: 0 !important;
}

.ds-page-head__text { min-width: 0; flex: 1 1 320px; }

.ds-page-head__title,
.ds-page > .page-top-heading h1 {
    margin: 0;
    color: var(--ds-text);
    font-size: 21px;
    font-weight: 600;
    letter-spacing: -0.024em;
    line-height: 1.25;
}

/* In-page headings that repeat the topbar title stay quieter. */
.ds-page > .page-top-heading h1 { font-size: 17px !important; }

.ds-page-head__text > :first-child { margin-top: 0; }

.ds-page-head__desc {
    margin: var(--ds-space-2) 0 0;
    max-width: 62ch;
    color: var(--ds-text-muted);
    font-size: 14px;
}

.ds-page-head__actions,
.ds-page > .page-top-heading > .d-flex,
.ds-page > .page-top-heading > div:last-child:not(:first-child) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ds-space-2);
}

/* ---------- rhythm ---------- */

.ds-section { margin-top: var(--ds-space-8); }
.ds-section:first-child { margin-top: 0; }
.ds-section--tight { margin-top: var(--ds-space-6); }
.ds-section--loose { margin-top: var(--ds-space-10); }

.ds-stack { display: flex; flex-direction: column; gap: var(--ds-space-4); }
.ds-stack > * { margin-top: 0 !important; margin-bottom: 0 !important; }
/* Includes written for a Bootstrap row (a .col-* wrapper) sit flush. */
.ds-stack > [class*="col-"] { padding-left: 0; padding-right: 0; }
.ds-stack--lg { gap: var(--ds-space-6); }

.ds-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--ds-space-4);
    align-items: start;
}

.ds-split > * { min-width: 0; }
.ds-split--stretch { align-items: stretch; }

@media (max-width: 859.98px) {
    .ds-split { grid-template-columns: minmax(0, 1fr); }
}

/* Alerts at the top of a page keep one gap to whatever follows. */
.ds-page > .alert,
.ds-page > .alert-messages,
.ds-page > .row:has(> .col-sm-12 > .alert) { margin-bottom: var(--ds-space-4); }
.ds-page > .row:has(> .col-sm-12 > .alert) .alert:last-child { margin-bottom: 0; }

/* ---------- forms ---------- */

.ds-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--ds-space-4);
}

.ds-form-grid > * { min-width: 0; margin: 0; }
.ds-form-grid > .ds-form-grid__full { grid-column: 1 / -1; }
.ds-form-grid label { display: block; margin-bottom: 6px; }

@media (max-width: 599.98px) {
    .ds-form-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Forms rendered by the shared include in a Bootstrap row, one per line. */
.ds-fields-1col > .row > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }

.ds-form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--ds-space-2);
    margin-top: var(--ds-space-6);
}

/* Upload forms: tabs, then the form card, with one gap between. */
.ds-page .tab-style > .tab-pane > .card,
.ds-page .tab-content > .tab-pane > .card { margin-top: var(--ds-space-4); }

/* The old templates nest a card in a card around each form; only the inner
   one should draw. */
.ds-page .card > .card {
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
}

/* ---------- toolbar and tables ---------- */

.ds-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-2) var(--ds-space-3);
    margin: 0 0 var(--ds-space-4) !important;
    padding: 0 !important;
}

.ds-toolbar__group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ds-space-2);
    min-width: 0;
}

.ds-toolbar__group--end { margin-left: auto; }
.ds-toolbar form { margin: 0; }
.ds-toolbar .form-control, .ds-toolbar select { width: auto; max-width: 100%; }

@media (max-width: 575.98px) {
    .ds-toolbar__group--end { margin-left: 0; }
    .ds-toolbar .ds-toolbar__group, .ds-toolbar form { flex: 1 1 100%; }
}

.ds-table-wrap,
.ds-page .table-responsive,
.ds-page .table-style,
.ds-page .scrollable-table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ds-table-wrap > .table, .ds-table-wrap > table { margin-bottom: 0; }

/* Grid and flex children default to their content's width; a wide table
   inside one would otherwise stretch the page. */
.ds-page .d-grid > *,
.ds-page .row > [class*="col"],
.ds-page .tab-content,
.ds-page .tab-pane { min-width: 0; }

/* Forms and navigation shrink with the page; wide tables keep their own scroll. */
#content :is(.nav-tabs, .nav-pills, .top-pages-btn) { flex-wrap: wrap; }
#content :is(.nav-tabs, .nav-pills, .top-pages-btn) .nav-link {
    white-space: normal;
    overflow-wrap: anywhere;
}
#content :is(.form-control, .form-select, textarea, input[type="file"]) {
    max-width: 100%;
    min-width: 0;
}

/* DataTables puts the table in a .col-sm-12 of its own; that column is the
   one that scrolls, so the search box and pager stay put. */
.ds-page .dataTables_wrapper { max-width: 100%; }
.ds-page .dataTables_wrapper .col-sm-12:has(> table) { overflow-x: auto; }
.ds-page .dataTables_wrapper > .row { margin-left: 0; margin-right: 0; row-gap: var(--ds-space-2); }
.ds-page .dataTables_wrapper > .row > [class*="col-"] { padding-left: 0; padding-right: 0; }
.ds-page .dataTables_wrapper .dataTables_filter input { max-width: 100%; }

@media (max-width: 767.98px) {
    .ds-page .dataTables_wrapper .dataTables_length,
    .ds-page .dataTables_wrapper .dataTables_filter,
    .ds-page .dataTables_wrapper .dataTables_info,
    .ds-page .dataTables_wrapper .dataTables_paginate { text-align: left !important; }
    .ds-page .dataTables_wrapper .dataTables_paginate .pagination { flex-wrap: wrap; justify-content: flex-start !important; }
}

/* ---------- cards ---------- */

.ds-page .card-body { padding: var(--ds-space-4); }
.ds-page .card-header { padding: var(--ds-space-3) var(--ds-space-4); }
.ds-page .card-footer { padding: var(--ds-space-3) var(--ds-space-4); }

/* A header inside a padded .card-style card sits flush with its edges. */
.ds-page .card-style > .card-header {
    margin: calc(-1 * var(--ds-space-4)) calc(-1 * var(--ds-space-4)) var(--ds-space-4);
}

.ds-page .card-style + .card-style,
.ds-page .card + .card { margin-top: var(--ds-space-4); }

/* Stacked spacing is for cards in normal flow; in a grid or flex row the gap
   already separates them, and a top margin would push every card after the
   first out of line. */
.ds-page :is(.flex-card, .ds-stat-grid, .pricing-container, .ds-tool-grid, .ds-offer-grid, .ds-split, .row) > :is(.card, .card-style) {
    margin-top: 0;
}

/* ---------- stat and chart grids ---------- */

.ds-stat-grid,
.ds-page .flex-card {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
    gap: var(--ds-space-3);
}

.ds-stat-grid--charts,
.ds-page .flex-card { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }

@media (min-width: 1024px) {
    .ds-stat-grid, .ds-page .flex-card { gap: var(--ds-space-4); }
}

.ds-stat-grid > * { min-width: 0; margin: 0 !important; }
.ds-stat-grid > a,
.ds-stat-grid > a:hover { color: inherit; text-decoration: none; }
.ds-stat-grid > * > .card-style { height: 100%; }

/* GST services tiles: icon, then label and number. */
.ds-stat-grid .card-style:has(> .icon-box) {
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
}
.ds-stat-grid .icon-box { flex: none; }
.ds-stat-grid .content-area { min-width: 0; }
.ds-stat-grid .content-area h6 { margin: 0 0 var(--ds-space-1); color: var(--ds-text-muted); font-size: 12px; font-weight: 500; }
.ds-stat-grid .content-area h3 { color: var(--ds-text); font-size: 21px; font-weight: 600; letter-spacing: -0.02em; }
.ds-stat-grid > a > .card-style { transition: border-color 0.12s var(--ds-ease), box-shadow 0.12s var(--ds-ease); }
.ds-stat-grid > a:hover > .card-style { border-color: var(--ds-border-strong) !important; box-shadow: var(--ds-shadow) !important; }
.ds-stat-grid > .disabled { opacity: 0.6; }

.ds-page .flex-card + *,
.ds-stat-grid + * { margin-top: var(--ds-space-6); }

/* ---------- dashboard ---------- */

/* The tool grid goes from one to four columns as the page widens; the
   Activity column joins on the right once there is room for both. */
.ds-page.ds-dashboard .ds-tool-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
}

/* ---------- auth ---------- */

/* One centred card, vertically centred in the viewport. */
.form-container,
.ds-auth {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    margin: 0 !important;
    padding: var(--ds-space-10) var(--ds-gutter);
}

.form-container .main-form,
.ds-auth__card { width: 100%; max-width: 400px; }

/* Sign-up has more fields; it gets the narrow measure and two columns. */
.form-container .main-form.ds-auth__card--wide { max-width: var(--ds-narrow-width); }

.ds-auth__card {
    padding: 28px;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-bg);
    box-shadow: var(--ds-shadow);
}

.ds-auth-page, .ds-auth { background: var(--ds-bg-subtle); }
.ds-auth__logo { display: block; width: 28px; height: 28px; border-radius: 7px; }

.ds-auth__messages { width: 100%; max-width: 400px; margin-bottom: var(--ds-space-4); }
.ds-auth__title { margin: 16px 0 4px; color: var(--ds-text); font-size: 17px; font-weight: 600; letter-spacing: -0.018em; }
.ds-auth__text { margin: 0 0 20px; color: var(--ds-text-muted); font-size: 13px; }
.ds-auth__links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--ds-space-2); margin-top: var(--ds-space-4); font-size: 12px; }
.ds-auth__card .btn-block + .btn-block { margin-top: var(--ds-space-2); }

@media (max-width: 575.98px) {
    .ds-auth__card, .form-container .main-form { padding: 20px; }
}

/* ---------- modals ---------- */

/* Every dialog is centred, with three widths: sm 400, default 520, lg 800. */
.modal-dialog:not(.modal-dialog-scrollable) {
    display: flex;
    align-items: center;
    min-height: calc(100% - 1rem);
}

@media (min-width: 576px) {
    .modal-dialog { max-width: 520px; margin-left: auto; margin-right: auto; }
    .modal-dialog:not(.modal-dialog-scrollable) { min-height: calc(100% - 3.5rem); }
    .modal-sm { max-width: 400px; }
    .modal-lg { max-width: min(800px, calc(100vw - 32px)); }
}

@media (min-width: 1200px) {
    .modal-xl { max-width: 1140px; }
}

/* A body under a header lines up with the header's title. */
.modal-content:has(> .modal-header) > .modal-body { padding: 16px 20px; }

.modal-content:has(> .modal-header) > .modal-body { padding: 16px 20px; }

/* ---------- Topbar client: company name and GSTN ---------- */
nav.navbar.topbar .nav-item .ds-client-name,
nav.navbar.topbar .nav-item .ds-client-id {
    font-weight: 600 !important;
    line-height: 1.3 !important;
    color: var(--ds-text) !important;
}

nav.navbar.topbar .nav-item .ds-client-name { font-size: 18px !important; }
nav.navbar.topbar .nav-item .ds-client-id   { font-size: 14px !important; }

nav.navbar.topbar .nav-item #fileUploadType {
    font-weight: 400 !important;
    font-size: 12px !important;
    color: var(--ds-text-muted) !important;
}
