@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap");

/* CEMCO shared theme: colors, type, header and form tabs.
   Pages opt in with <body class="app"> and includes/app_header.php.
   Colors come from the CEMCO logo: blue bar, black type, cool gray. */

:root {
    /* Brand */
    --brand-blue:        #0070b8;
    --brand-blue-dark:   #005a94;
    --brand-blue-tint:   #e8f1f8;
    --brand-ink:         #16191d;

    /* Neutrals (cool gray, low glare for all-day use) */
    --canvas:            #eef1f4;
    --surface:           #ffffff;
    --surface-muted:     #f6f8fa;
    --line:              #d6dce2;
    --line-strong:       #bcc4cc;
    --text:              #1f2429;
    --text-muted:        #5f6b76;

    /* Nav strip */
    --nav-bg:            #1f2429;
    --nav-text:          #c9d1d9;

    --radius:            6px;
    --shadow-sm:         0 1px 2px rgba(16, 24, 32, 0.06);
    --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.app {
    margin: 0;
    min-height: 100vh;
    background: var(--canvas);
    color: var(--text);
    font-family: var(--font);
    font-variant-numeric: tabular-nums; /* every digit the same width, so numbers line up */
    font-size: 15px;
    line-height: 1.5;
}

/* Inputs, buttons and lists don't inherit type settings by themselves */
body.app :is(input, select, textarea, button),
body.login-page :is(input, select, textarea, button) {
    font-family: var(--font);
    font-variant-numeric: tabular-nums;
}

/* ---------- Header ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 1030; /* above Bootstrap content, below modals (1050) */
    background: var(--surface);
    box-shadow: 0 1px 0 var(--line);
}

.app-header__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 56px;
    padding: 0 24px;
}

.app-header__brand {
    display: flex;
    align-items: center;
}

.app-header__logo {
    height: 32px;
    width: auto;
    display: block;
}

.app-header__user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    white-space: nowrap;
}

.app-header__user-label {
    color: var(--text-muted);
}

.app-header__user-name {
    font-weight: 600;
    color: var(--text);
}

.app-header__logout {
    margin-left: 8px;
    padding: 5px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.app-header__logout:hover {
    background: #fbeaea;
    border-color: #c0392b;
    color: #a12c20;
    text-decoration: none;
}

/* ---------- Form tabs ---------- */

.app-nav {
    display: flex;
    overflow-x: auto;
    background: var(--nav-bg);
    border-bottom: 3px solid var(--brand-blue); /* echoes the logo's blue bar */
    padding: 0 12px;
    scrollbar-width: thin;
}

.app-nav__link {
    flex: 0 0 auto;
    padding: 11px 16px;
    color: var(--nav-text);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}

.app-nav__link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
}

.app-nav__link.is-active {
    background: var(--brand-blue);
    color: #fff;
}

/* ---------- Page area ---------- */

.app-main {
    padding: 20px 24px 32px;
}

.app-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

/* Shared buttons for themed pages */
.app-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.app-btn--primary {
    background: var(--brand-blue);
    color: #fff;
}

.app-btn--primary:hover {
    background: var(--brand-blue-dark);
    color: #fff;
    text-decoration: none;
}

.app-btn:focus-visible,
.app-nav__link:focus-visible,
.app-header__logout:focus-visible {
    outline: 2px solid var(--brand-blue);
    outline-offset: 2px;
}

/* ---------- Live updates (js/shared/live_updates.js) ---------- */

.live-toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 2000;
    max-width: 420px;
    padding: 10px 14px;
    border-left: 4px solid var(--brand-blue);
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    color: var(--brand-ink);
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.live-toast.is-shown {
    opacity: 1;
    transform: none;
}

@keyframes live-flash {
    from { background-color: #fff1b8; }
    to   { background-color: transparent; }
}

tr.live-flash > td {
    animation: live-flash 2.5s ease-out;
}

/* ---------- Excel preview (js/shared/excel_preview.js) ---------- */
.xp-dialog {
    width: min(1200px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 0;
    border-top: 4px solid var(--brand-blue);
    border-radius: 10px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
    color: var(--text);
    font-family: var(--font);
}

.xp-dialog[open] {
    display: flex;
    flex-direction: column;
}

.xp-dialog::backdrop {
    background: rgba(3, 8, 12, 0.45);
}

.xp-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 14px;
    padding: 16px 20px 6px;
}

.xp-title {
    margin: 0;
    color: var(--brand-ink);
    font-size: 18px;
    font-weight: 700;
}

.xp-file {
    color: var(--text-muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.xp-tabs {
    display: flex;
    gap: 4px;
    padding: 6px 20px 0;
}

.xp-tab {
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-muted);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.xp-tab[aria-selected="true"] {
    border-color: var(--brand-blue);
    background: var(--brand-blue-tint);
    color: var(--brand-blue-dark);
    font-weight: 600;
}

.xp-count {
    padding: 8px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.xp-body {
    flex: 1;
    min-height: 120px;
    margin: 0 20px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.xp-dialog .xp-table {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
}

.xp-dialog .xp-table th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.xp-dialog .xp-table td,
.xp-dialog .xp-table th {
    max-width: 420px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.xp-table .xp-empty {
    color: var(--text-muted);
    font-style: italic;
}

.xp-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px 16px;
}

/* Main lists moved through with the mouse wheel (RLOG, Sales, Quotation): no scrollbar; the wheel moves
   the highlighted row like the arrow keys, and the list keeps that row in view */
div.fm-wheel-list {
    scrollbar-width: none;
    scrollbar-gutter: auto;
}

div.fm-wheel-list::-webkit-scrollbar {
    display: none;
}

/* ---------- Tablet view (html.tablet: includes/app_header.php, js/shared/touch.js) ---------- */
.app-header__view {
    padding: 6px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.app-header__view:hover {
    border-color: var(--brand-blue);
    color: var(--brand-blue-dark);
}

/* no double-tap zoom (taps answer at once), no zooming in when a field is tapped (iOS zooms into text under 16px) */
html.tablet {
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

html.tablet input,
html.tablet select,
html.tablet textarea {
    font-size: 16px;
}

/* the top menu: swipe it sideways; the faded right edge says there are more tabs */
html.tablet .app-nav {
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
}

html.tablet .app-nav::-webkit-scrollbar {
    display: none;
}

html.tablet .app-nav__link {
    padding: 14px 18px;
}

/* fingertip-sized buttons and rows */
html.tablet .fm-btn,
html.tablet .app-header__logout,
html.tablet .app-header__view {
    min-height: 44px;
    padding-left: 16px;
    padding-right: 16px;
}

html.tablet .fm-table td {
    height: 40px;
}

/* holding a cell opens it (no iOS copy menu, no text selection outside fields) */
html.tablet table td {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html.tablet table td input,
html.tablet table td textarea,
html.tablet table td [contenteditable="true"],
html.tablet table td[contenteditable="true"] {
    -webkit-user-select: text;
    user-select: text;
}

/* keyboard-shortcut hints (F9, Ctrl+Space, PgUp...): there's no keyboard */
html.tablet .fm-tip,
html.tablet .rl-tip {
    display: none;
}

html.tablet .fm-wheel-list {
    touch-action: pan-x;   /* up / down swipes move through the records (touch.js); sideways still scrolls */
}

html.tablet .app-header__logout {
    display: inline-flex;
    align-items: center;
}

/* Text for one view only (instructions): .for-computer shows in Computer view, .for-tablet in Tablet view */
html.tablet .for-computer,
html:not(.tablet) .for-tablet {
    display: none !important;
}

/* Tablet view: what to tap, in place of the keyboard hint line (added by js/shared/touch.js) */
.fm-tip-touch {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.4;
}
