/* ==========================================================================
   Mobile app shared styles (no Tailwind).
   Screen-specific rules live in css/<screen>.css.
   ========================================================================== */

:root {
    --primary: #0A1628;
    --primary-soft: #16243c;
    --accent: #8EB736;
    --accent-dark: #6f9128;
    --teal: #00504A;
    --danger: #E84C22;
    --warn: #d98a00;

    --bg: #f4f6f9;
    --surface: #ffffff;
    --line: #e4e8ef;
    --text: #16202e;
    --muted: #66748a;

    --ok-bg: #e8f5e9;
    --ok-fg: #256b2b;
    --warn-bg: #fdf3e0;
    --warn-fg: #8a5b00;
    --danger-bg: #fdeae5;
    --danger-fg: #a83212;

    --radius: 12px;
    --radius-lg: 16px;
    --shadow: 0 1px 2px rgba(16, 32, 55, .06), 0 6px 18px rgba(16, 32, 55, .06);
    --shadow-lg: 0 12px 40px rgba(16, 32, 55, .22);
    --header-h: 52px;
    --nav-h: 62px;
}

* { box-sizing: border-box; }

/* Author display rules (e.g. .m-modal { display:flex }) must not defeat the
   HTML `hidden` attribute, which is how the modal/toast start out hidden. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body.m-app {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
    min-height: 100vh;
}

/* ---------------------------------------------------------------- Header -- */
.m-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    height: var(--header-h);
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 10px rgba(6, 16, 32, .28);
}
.m-header__brand {
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .55);
}
.m-header__title {
    font-size: 17px;
    font-weight: 700;
}

/* ------------------------------------------------------------------ Main -- */
.m-main {
    display: block;
    padding: 16px;
    padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
    max-width: 640px;
    margin: 0 auto;
}

/* --------------------------------------------------------------- Bottom nav */
.m-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    background: var(--primary);
    border-top: 1px solid rgba(255, 255, 255, .08);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -6px 20px rgba(6, 16, 32, .25);
}
.m-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: var(--nav-h);
    color: rgba(255, 255, 255, .55);
    text-decoration: none;
    font-size: 9.5px;
    font-weight: 600;
    transition: color .15s ease;
}
.m-nav__item svg { width: 21px; height: 21px; }
.m-nav__item[aria-current="page"] { color: #fff; }
.m-nav__item[aria-current="page"]::after {
    content: "";
    width: 16px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
    margin-top: 1px;
}

/* ----------------------------------------------------------------- Cards -- */
.m-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}
.m-card--tight { padding: 12px; }

.m-section-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 4px 0 10px;
}

/* -------------------------------------------------------------- List rows -- */
.m-list { display: flex; flex-direction: column; gap: 10px; }

.m-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
}
.m-row--plain {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0 0 12px;
}
.m-row__avatar {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    overflow: hidden;
}
.m-row__avatar img { width: 100%; height: 100%; object-fit: cover; }
.m-row__main { flex: 1 1 auto; min-width: 0; }
.m-row__name {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.m-row__sub {
    color: var(--muted);
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.m-row__meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.m-row__side { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.row-actions { flex-direction: row; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.row-actions .m-btn { white-space: nowrap; }

@media (max-width: 430px) {
    .row-actions { flex-direction: column; align-items: flex-end; }
}

.m-serial {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
    background: #f1f4f8;
    border-radius: 6px;
    padding: 1px 6px;
}

/* ---------------------------------------------------------------- Badges -- */
.m-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
    line-height: 1.4;
}
.m-badge--ok { background: var(--ok-bg); color: var(--ok-fg); }
.m-badge--warn { background: var(--warn-bg); color: var(--warn-fg); }
.m-badge--danger { background: var(--danger-bg); color: var(--danger-fg); }
.m-badge--muted { background: #eef1f5; color: var(--muted); }
.m-badge--role { background: #e7edf7; color: #2c4a7c; }
.m-badge--super { background: #efe6ff; color: #5b34a8; }

.m-chip {
    font-size: 11px;
    color: var(--muted);
    background: #f1f4f8;
    border-radius: 999px;
    padding: 2px 8px;
}

/* --------------------------------------------------------------- Buttons -- */
.m-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    background: #eef1f5;
    color: var(--text);
    transition: filter .15s ease, background .15s ease;
}
.m-btn:active { filter: brightness(.96); }
.m-btn--primary { background: var(--primary); color: #fff; }
.m-btn--accent { background: var(--accent); color: #10240a; }
.m-btn--danger { background: var(--danger); color: #fff; }
.m-btn--ghost { background: transparent; border-color: var(--line); color: var(--text); }
.m-btn--sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.m-btn--block { width: 100%; }
.m-btn[disabled] { opacity: .55; cursor: default; }

/* ---------------------------------------------------------------- Forms --- */
.m-field { display: block; margin-bottom: 12px; }
.m-field__label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 5px;
}
.m-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    padding: 11px 12px;
    font-size: 15px;
    color: var(--text);
    font-family: inherit;
}
.m-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(142, 183, 54, .18);
}
.m-input[disabled] { background: #f4f6f9; color: var(--muted); }

.m-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* --------------------------------------------------------------- Toolbar -- */
.m-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.m-toolbar .m-input { flex: 1 1 auto; }

.m-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    margin-bottom: 12px;
    -webkit-overflow-scrolling: touch;
}
.m-tab {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: 7px 13px;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.m-tab.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* --------------------------------------------------------------- Stats ---- */
.m-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.m-grid--3 { grid-template-columns: repeat(3, 1fr); gap: 8px; }

.m-stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}
.m-stat--tight { padding: 10px; }
.m-stat--tight .m-stat__value { font-size: 20px; }
.m-stat__label {
    font-size: 11.5px;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.m-stat__value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.m-stat__hint { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.m-stat--accent .m-stat__value { color: var(--accent-dark); }
.m-stat--teal .m-stat__value { color: var(--teal); }
.m-stat--danger .m-stat__value { color: var(--danger); }
.m-stat--warn .m-stat__value { color: var(--warn); }

.m-progress {
    height: 6px;
    border-radius: 999px;
    background: #eef1f5;
    overflow: hidden;
    margin-top: 8px;
}
.m-progress__bar { height: 100%; background: var(--accent); border-radius: 999px; }

/* --------------------------------------------------------------- Pager ---- */
.m-pager { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 16px 0 4px; }
.m-pager__info { font-size: 12px; color: var(--muted); }

/* -------------------------------------------------------------- Feedback --- */
.m-empty,
.m-loading {
    text-align: center;
    color: var(--muted);
    padding: 28px 12px;
    font-size: 13.5px;
}
.m-error {
    background: var(--danger-bg);
    color: var(--danger-fg);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 12px;
}
.m-skeleton {
    height: 62px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, #eef1f5 25%, #e3e8ef 37%, #eef1f5 63%);
    background-size: 400% 100%;
    animation: m-shimmer 1.3s ease infinite;
}
@keyframes m-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ---------------------------------------------------------------- Modal --- */
.m-modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.m-modal__backdrop { position: absolute; inset: 0; background: rgba(8, 16, 30, .5); }
.m-modal__panel {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 88vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    box-shadow: var(--shadow-lg);
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    animation: m-slide-up .2s ease;
}
@keyframes m-slide-up {
    from { transform: translateY(24px); opacity: .6; }
    to { transform: translateY(0); opacity: 1; }
}
.m-modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.m-modal__title { font-size: 17px; font-weight: 800; margin: 0; }
.m-modal__close {
    border: none;
    background: #eef1f5;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
}
.m-dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13.5px; }
.m-dl dt { color: var(--muted); font-weight: 600; }
.m-dl dd { margin: 0; font-weight: 600; word-break: break-word; }

/* ---------------------------------------------------------------- Toast --- */
.m-toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 70;
    max-width: 90vw;
    background: var(--primary);
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: m-toast-in .18s ease;
}
.m-toast--ok { background: #256b2b; }
.m-toast--error { background: #a83212; }
@keyframes m-toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------- Links --- */
.m-links { display: flex; flex-direction: column; }
.m-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 4px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 14.5px;
}
.m-link:last-child { border-bottom: 0; }
.m-link__chev { color: var(--muted); font-size: 20px; line-height: 1; }
.m-link--danger { color: var(--danger); }

/* -------------------------------------------------------------- Utilities - */
.m-h1 { font-size: 20px; font-weight: 800; margin: 0 0 4px; }
.m-sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.m-mt { margin-top: 14px; }
.m-mb-0 { margin-bottom: 0; }
.m-hidden { display: none !important; }
.m-text-muted { color: var(--muted); }
.m-row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.m-stack { display: flex; flex-direction: column; gap: 4px; }
.m-note {
    background: var(--warn-bg);
    color: var(--warn-fg);
    border: 1px solid #f0d9ae;
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 12.5px;
    margin-bottom: 12px;
}
