/*
 * EIISYS restrained module theme
 * ------------------------------
 * Presentation only. This stylesheet deliberately does not alter navigation
 * structure, module routing, menu membership, navigator grouping, or business
 * workflows. Each module defines --eis-module-* variables in config/css.php.
 */

:root {
    --eis-module: #0f766e;
    --eis-module-dark: #115e59;
    --eis-module-soft: #ccfbf1;
    --eis-module-rgb: 15, 118, 110;
    --eis-page-bg: #f5f7f9;
    --eis-surface: #ffffff;
    --eis-text: #1f2937;
    --eis-muted: #64748b;
    --eis-border: #dfe5ea;
    --eis-radius: 8px;
    --eis-shadow: 0 2px 8px rgba(15, 23, 42, .07);
}

html { background: var(--eis-page-bg); }
body {
    background: var(--eis-page-bg);
    color: var(--eis-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Keep the legacy W3 navigation and all menu positions exactly as coded. */
.w3-top .w3-bar.w3-teal,
.w3-top > .w3-bar {
    background-color: var(--eis-module) !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .16);
}

.w3-top .w3-bar .w3-button {
    transition: background-color .15s ease, color .15s ease;
}

.w3-top .w3-bar .w3-button:hover,
.w3-top .w3-dropdown-hover:hover > .w3-button,
.w3-top .w3-dropdown-hover:hover > a.w3-button {
    background-color: var(--eis-module-dark) !important;
    color: #fff !important;
}

.w3-dropdown-content {
    border: 1px solid var(--eis-border);
    border-top: 3px solid var(--eis-module);
    border-radius: 0 0 6px 6px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .14) !important;
    overflow: hidden;
}

.w3-dropdown-content .w3-bar-item {
    color: #263238 !important;
}

.w3-dropdown-content .w3-bar-item:hover {
    background: var(--eis-module-soft) !important;
    color: var(--eis-module-dark) !important;
}

/* Existing W3 cards/panels get polish without changing their dimensions/layout. */
.w3-card,
.w3-card-2,
.w3-card-4 {
    border-radius: var(--eis-radius);
    box-shadow: var(--eis-shadow) !important;
}

.w3-white.w3-card,
.w3-white.w3-card-2,
.w3-white.w3-card-4 {
    border: 1px solid var(--eis-border);
}

.w3-panel,
.w3-container {
    scrollbar-color: #cbd5e1 transparent;
}

/* Forms stay familiar, just clearer and more consistent. */
.w3-input,
.w3-select {
    border-radius: 5px;
    border-color: #cbd5e1 !important;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.w3-input:focus,
.w3-select:focus {
    border-color: var(--eis-module) !important;
    box-shadow: 0 0 0 2px rgba(var(--eis-module-rgb), .12);
    outline: none;
}

button.w3-button,
a.w3-button,
input.w3-button {
    border-radius: 5px;
}

.w3-button.w3-teal,
.w3-teal.w3-button,
button.w3-teal,
a.w3-teal {
    background-color: var(--eis-module) !important;
}

.w3-button.w3-teal:hover,
.w3-teal.w3-button:hover,
button.w3-teal:hover,
a.w3-teal:hover {
    background-color: var(--eis-module-dark) !important;
}

/* Module accent is available to modern navigator tiles already present in EIISYS. */
.tile-btn:hover,
.action-btn:hover {
    border-color: rgba(var(--eis-module-rgb), .28) !important;
}

.tile-icon,
.w3-text-teal {
    color: var(--eis-module) !important;
}

.w3-border-teal {
    border-color: var(--eis-module) !important;
}

/* Tables retain all existing columns, controls and DataTables behavior. */
.w3-table-all,
.w3-table,
table.dataTable {
    background: var(--eis-surface);
}

.w3-table-all {
    border-color: var(--eis-border) !important;
}

.w3-table-all thead th,
.w3-table thead th,
table.dataTable thead th {
    color: #334155;
}

/* Footer remains in its original place and structure. */
.footer {
    border-top: 1px solid var(--eis-border);
    color: var(--eis-muted);
}

/* Small screens: do not introduce a new navigation system; improve only spacing. */
@media (max-width: 600px) {
    .w3-content {
        margin-left: 8px !important;
        margin-right: 8px !important;
    }
}

@media print {
    .w3-top { box-shadow: none !important; }
}

/* ---------------------------------------------------------------------------
 * Responsive type scale
 *
 * W3.CSS pins its size utilities to fixed pixels -- .w3-xxlarge is
 * `font-size:36px!important` -- so they do not answer to the viewport at all.
 * That is fine until something sized that way has to share a row: the filter
 * button on Store -> Branch(es) Valuation is `w3-btn w3-blue-grey w3-xxlarge`
 * in a `w3-col m2`, and an m-column keeps its percentage all the way down to
 * 601px. A 36px "View Data" needs about 227px; the column offers 200px at a
 * 1200px window and less as the window narrows, so the button grew out of its
 * column. The same fixed 36px sits on 52 heading icons across the modules.
 *
 * Each clamp below reaches its ORIGINAL value on a desktop-width window and
 * only gives way on narrower ones, so nothing gets smaller where there was
 * room for it and nothing anywhere gets bigger:
 *
 *     .w3-xlarge    24px at >=  818px
 *     .w3-xxlarge   36px at >= 1111px
 *     .w3-xxxlarge  48px at >= 1208px
 *     .w3-jumbo     64px at >= 1206px
 *
 * Only .w3-xlarge and .w3-xxlarge are used in the modules today; the other
 * two are here so the next person to reach for one gets the same behaviour.
 *
 * !important is needed to reach past W3's own, and matches how this file
 * already re-points .w3-text-teal and .w3-border-teal at the module colour.
 */
.w3-xlarge { font-size: clamp(19px, 1.1vw + 15px, 24px) !important; }
.w3-xxlarge { font-size: clamp(24px, 1.8vw + 16px, 36px) !important; }
.w3-xxxlarge { font-size: clamp(30px, 2.4vw + 19px, 48px) !important; }
.w3-jumbo { font-size: clamp(38px, 3.4vw + 23px, 64px) !important; }

/*
 * A button laid out in a grid column stays inside that column. .w3-btn is
 * `white-space:nowrap; overflow:hidden`, so without this a label too wide for
 * its column is cut off mid-word rather than wrapped. Nothing here widens a
 * button -- max-width only constrains, and white-space only wraps a label
 * that was going to be clipped anyway.
 *
 * Scoped to .w3-col, not to the form, because the hazard is the column: of
 * the enlarged filter buttons, 87 sit in a `form[role="search"]` and 31 in
 * forms carrying no role at all, and both kinds are laid out the same way.
 *
 * It covers the ordinary-sized buttons too, which turn out to have had the
 * same fault all along -- a plain `w3-btn` reading "Plain Button" overflows a
 * `w3-col m2` by 12px once the window is down to 601px, and 289 of those are
 * in the modules.
 *
 * overflow-wrap is for the long labels: a word wider than the column would
 * otherwise be clipped rather than broken.
 *
 * break-word, NOT anywhere. The two break identically once a line is too
 * narrow, but `anywhere` also counts toward intrinsic width, so an
 * inline-block button shrink-to-fits down to its widest CHARACTER and the
 * label then wraps even where it would have fitted. That is what split
 * "Proceed" across two lines between 601 and 768px while the room for it was
 * there. break-word leaves intrinsic sizing alone.
 */
.w3-col .w3-btn,
.w3-col .w3-button,
.w3-col button.w3-btn,
.w3-col input.w3-btn,
/*
 * And any button carrying a size class, column or not. 51 of them are not in
 * one: the Finance, HRM and Production "Proceed" pages stack each field in a
 * full-width w3-row instead, so none of the .w3-col rules above reach them.
 * There is room to spare in a full-width row, but the guard costs nothing
 * and the next narrow container should not have to rediscover this.
 */
.w3-btn.w3-xlarge, .w3-button.w3-xlarge,
.w3-btn.w3-xxlarge, .w3-button.w3-xxlarge,
.w3-btn.w3-xxxlarge, .w3-button.w3-xxxlarge,
.w3-btn.w3-jumbo, .w3-button.w3-jumbo {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: break-word;
}

/*
 * A button in a column needs a steeper curve than a heading does, because it
 * has to hold a whole word on one line inside a sixth of the row rather than
 * simply get smaller.
 *
 * Derived by measurement, not estimate. The binding label is "Proceed" -- 52
 * of these -- which renders 3.59px wide per 1px of font-size in the theme's
 * font. A `w3-col m2` gives it 16.666% of the window less 32px of column
 * padding, and the button spends another 32px on its own, so the largest
 * size that keeps the word whole is
 *
 *     (0.16666 * viewport - 64) / 3.59   =   4.64vw - 17.8px
 *
 * The 64px of padding is the part a first attempt here missed: the column
 * carries w3-padding as well as the button, and leaving it out put the curve
 * about 10px high, which broke "Proceed" anywhere below 1160px.
 *
 * The floor is 15px, which is W3's own default button size and is reached at
 * a 707px window.
 *
 * It fills its column rather than shrink-to-fitting. That is partly how the
 * filter row wants to look, and partly because a shrink-to-fit inline-block
 * takes its width from the text's own min-content, which Chrome narrows when
 * overflow-wrap is set -- so "Proceed" split across two lines at 900px even
 * though 106px of room was there for an 86px word. A column-width button has
 * no such dependence.
 *
 * It does not rescue a `w3-col m1`. That column is 8.33% -- about 68px of
 * usable text at a 1200px window -- which will not hold "Search" even at the
 * default 15px, so those 25 buttons are deliberately left alone. They are a
 * layout fault, not a type fault: the column needs widening. All this does
 * for them is keep them inside it instead of overlapping the next column.
 */
.w3-col .w3-btn.w3-xxlarge,
.w3-col .w3-button.w3-xxlarge {
    display: block;
    width: 100%;
    font-size: clamp(15px, 4.64vw - 17.8px, 36px) !important;
}

/*
 * Below about 992px the padding is the problem rather than the type. A
 * `w3-col m2` at a 700px window is 117px wide, and the column's own
 * w3-padding takes 32px of that while the button's takes another 32, leaving
 * 53px for the word -- less than "Proceed" needs even at 15px, so it would
 * break mid-word. Trimming the button's side padding there returns 20px,
 * which is enough to keep the word whole down to the point where W3 drops
 * the columns to full width anyway.
 */
@media (max-width: 992px) {
    .w3-col .w3-btn.w3-xxlarge,
    .w3-col .w3-button.w3-xxlarge {
        /* !important because many of these also carry w3-padding, which W3
         * declares !important; without it this rule silently lost and the
         * button kept all 32px. */
        padding-right: 6px !important;
        padding-left: 6px !important;
    }
}

/* ---------------------------------------------------------------------------
 * Report context lines
 *
 * A report page states which branch and date it is showing above its table.
 * The newer pages do it in markup -- Store -> Branch(es) Valuation has
 * `<header class="w3-padding-large w3-large w3-border-bottom">` -- while 261
 * older pages put the same sentence in `<caption><p>Branch: ... Date: ...</p>`
 * and no stylesheet has ever touched it, so a browser renders it centred, at
 * body size, with a paragraph's margin under it.
 *
 * Styling the caption gives those pages the newer treatment without editing
 * them. It is the same left-aligned, ruled line, and it stays a <caption>,
 * so screen readers still announce it as the table's name.
 */
.w3-table > caption,
.w3-table-all > caption {
    caption-side: top;
    padding: 14px 16px;
    border-bottom: 1px solid var(--eis-border);
    color: var(--eis-text);
    font-size: clamp(15px, .5vw + 13px, 18px);
    font-weight: 500;
    text-align: left;
}

.w3-table > caption p,
.w3-table-all > caption p {
    margin: 0;
}
