/*
 * Yigui Developer Cloud — Developer Portal (Phase 12.1).
 *
 * Hand-written and mobile-first. No framework is pulled in: the project ships
 * no frontend stack today, and adding one for a handful of read-only pages
 * would be a heavier commitment than the phase warrants (guide § 3).
 *
 * Layout order matters here — the small-screen rules are the base, and the
 * sidebar only becomes a fixed column once there is room for one.
 */

:root {
    /* ---------- Colour ----------
       Every colour carries meaning. `good`/`bad`/`busy`/`neutral` are the four
       states the whole product speaks in; nothing decorative lives here. */
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #dfe3e8;
    --text: #1b2330;
    --text-muted: #5b6676;
    --brand: #12324f;
    --brand-accent: #1f7ae0;
    --good: #1a7f4b;
    --good-bg: #e7f5ed;
    --bad: #b3261e;
    --bad-bg: #fdecea;
    --busy: #8a5a00;
    --busy-bg: #fdf3e0;
    --neutral: #55606e;
    --neutral-bg: #eceff3;

    /* ---------- Spacing ----------
       A 4px base. Nine steps replace the seventeen ad-hoc values this sheet
       had accumulated (.2, .3, .35, .55, .7, .85rem and so on) — spacing is
       what makes an interface read as deliberate, and a scale is the only way
       to keep it so as the surface grows. */
    --space-1: .25rem;   /*  4px */
    --space-2: .5rem;    /*  8px */
    --space-3: .75rem;   /* 12px */
    --space-4: 1rem;     /* 16px */
    --space-5: 1.25rem;  /* 20px */
    --space-6: 1.5rem;   /* 24px */
    --space-8: 2rem;     /* 32px */
    --space-10: 2.5rem;  /* 40px */
    --space-12: 3rem;    /* 48px */

    /* ---------- Typography ----------
       Seven levels, replacing seventeen sizes that included eight distinct
       values inside a 0.17rem span — a spread the eye reads as sloppiness
       rather than hierarchy.

       `--text-xs` is the floor at 12px: three rules previously sat at .72rem
       (11.5px), below comfortable reading size for the uppercase labels they
       were applied to. */
    --text-xs: .75rem;      /* 12px — badges, table headers, captions */
    --text-sm: .875rem;     /* 14px — secondary and meta text */
    --text-base: 1rem;      /* 16px — body, inputs, buttons */
    --text-lg: 1.125rem;    /* 18px — card and section titles */
    --text-xl: 1.25rem;     /* 20px — page subject */
    --text-2xl: 1.5rem;     /* 24px — page title */
    --text-3xl: 1.875rem;   /* 30px — a single headline figure */

    /* ---------- Radius ---------- */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-full: 999px;

    /* ---------- Elevation ----------
       Two steps, both deliberately faint. A control panel earns trust by
       looking precise, not by floating: anything heavier reads as decoration. */
    --shadow-sm: 0 1px 2px rgba(16, 22, 31, .05);
    --shadow-md: 0 1px 3px rgba(16, 22, 31, .07), 0 6px 16px rgba(16, 22, 31, .05);

    /* ---------- Motion ----------
       Short enough to feel like feedback rather than animation. The global
       prefers-reduced-motion rule at the end of this sheet disables both. */
    --transition-fast: 120ms ease;
    --transition-base: 180ms ease;

    /* ---------- Layers ---------- */
    --z-sticky: 20;
    --z-skip-link: 100;

    /* ---------- Breakpoints ----------
       Declared for the record only: CSS custom properties cannot be used
       inside a media query, so the values below are repeated literally in the
       @media rules. Stated rather than pretended otherwise.
         sm 700px · lg 1000px · xl 1280px */

    /* Kept as aliases so existing rules keep working unchanged. */
    --radius: var(--radius-lg);
    --gap: var(--space-4);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: var(--text-2xl); margin: 0; }
h2 { font-size: var(--text-lg); margin: 0 0 var(--space-3); }

a { color: var(--brand-accent); }

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9em;
    background: var(--neutral-bg);
    padding: .1em .35em;
    border-radius: var(--radius-sm);
}

/* Visible only to keyboard users, and only while focused. */
.skip-link {
    position: absolute;
    left: -9999px;
}
.skip-link:focus {
    left: .5rem;
    top: .5rem;
    z-index: var(--z-skip-link);
    background: var(--surface);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Topbar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    background: var(--brand);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    /* Only while it actually overlaps content, which is what elevation means. */
    box-shadow: var(--shadow-md);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: #fff;
    text-decoration: none;
    font-size: var(--text-base);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 28px; height: 28px;
    border-radius: var(--radius-md);
    background: var(--brand-accent);
    font-weight: 700;
}

.brand-text strong { font-weight: 700; }

.brand-lg { font-size: var(--text-lg); margin-bottom: var(--space-5); color: var(--brand); }
.brand-lg .brand-text { color: var(--brand); }

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.user-email {
    display: none;
    font-size: var(--text-sm);
    opacity: .85;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-form { margin: 0; }

.nav-toggle {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .35);
    color: #fff;
    border-radius: var(--radius-md);
    font-size: var(--text-lg);
    /* Comfortably tappable on a phone. */
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
}

/* ---------- Layout ---------- */

.layout { display: block; }

.sidebar {
    display: none;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-3);
}

.sidebar.is-open { display: block; }

.nav-list { list-style: none; margin: 0; padding: 0; }

.nav-link {
    display: block;
    padding: var(--space-3) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
    min-height: 44px;
}

.nav-link { transition: background var(--transition-fast), color var(--transition-fast); }
.nav-link:hover { background: var(--neutral-bg); }

.nav-link.is-active {
    background: var(--brand);
    color: #fff;
    font-weight: 600;
}

.nav-future {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.nav-future-title {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin: 0 0 var(--space-2);
}

.nav-future ul { list-style: none; margin: 0; padding: 0; }
.nav-future li { padding: var(--space-1) var(--space-1); }

.content { padding: var(--space-4) var(--space-4) var(--space-12); }

.page-head { margin-bottom: var(--space-4); }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--gap);
    /* A hairline, not a float: the card must read as a precise surface. */
    box-shadow: var(--shadow-sm);
}

.card-title { font-size: var(--text-lg); font-weight: 600; margin: 0 0 var(--space-2); }

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap);
    margin-bottom: var(--gap);
}

.two-col {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap);
}

.stat-card { margin-bottom: 0; }

.stat-label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin: 0 0 var(--space-1);
}

.stat-value { font-size: var(--text-3xl); font-weight: 700; margin: 0 0 var(--space-2); }

.stat-lines { margin: var(--space-2) 0 0; }

.stat-lines > div {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-1) 0;
    border-top: 1px solid var(--border);
    font-size: var(--text-sm);
}

.stat-lines dt { color: var(--text-muted); }
.stat-lines dd { margin: 0; text-align: right; }

.stat-link {
    display: inline-block;
    margin-top: var(--space-2);
    font-size: var(--text-sm);
}

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: .18em .6em;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: .02em;
}

.badge-good { background: var(--good-bg); color: var(--good); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-busy { background: var(--busy-bg); color: var(--busy); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Meters ---------- */

.meter { margin-bottom: var(--space-3); }

.meter-head {
    display: flex;
    justify-content: space-between;
    font-size: var(--text-sm);
    margin-bottom: var(--space-1);
}

.meter-label { color: var(--text-muted); }
.meter-value { font-weight: 600; }

.meter-track {
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--neutral-bg);
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    background: var(--good);
    border-radius: var(--radius-full);
}

.meter-fill.is-warning { background: var(--busy); }
.meter-fill.is-critical { background: var(--bad); }

.usage-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2) var(--space-6);
}

/* ---------- Alerts ---------- */

.alerts { margin-bottom: var(--gap); }

.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    border: 1px solid transparent;
}

.alert-danger { background: var(--bad-bg); color: var(--bad); border-color: #f3c5c1; }
.alert-warning { background: var(--busy-bg); color: var(--busy); border-color: #f0dcb0; }
.alert-info { background: #e8f1fd; color: #14508f; border-color: #c6dcf8; }

/* ---------- Empty / notes ---------- */

.empty-state {
    color: var(--text-muted);
    background: var(--neutral-bg);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin: 0;
}

.empty-hint { display: block; font-size: var(--text-sm); margin-top: var(--space-1); opacity: .9; }

.note { color: var(--text-muted); font-size: var(--text-sm); }

/* ---------- Tables ---------- */

/* Wide tables scroll inside their own box; the page never scrolls sideways. */
.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

th, td {
    text-align: left;
    padding: var(--space-2) var(--space-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th { color: var(--text-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Tags ---------- */

.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; padding: 0; }

.tag {
    background: var(--neutral-bg);
    color: var(--neutral);
    border-radius: var(--radius-full);
    padding: .2em .7em;
    font-size: var(--text-xs);
}

/* ---------- Forms & buttons ---------- */

.field { margin-bottom: var(--space-4); }

.field label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    margin-bottom: var(--space-1);
}

.field input {
    width: 100%;
    padding: var(--space-3) var(--space-3);
    font-size: var(--text-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    min-height: 44px;
}

.field input:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible,
a:focus-visible {
    outline: 3px solid var(--brand-accent);
    outline-offset: 2px;
}

.btn {
    display: inline-block;
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-base);
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    min-height: 44px;
    transition: background var(--transition-fast), border-color var(--transition-fast),
                transform var(--transition-fast);
}

/* Pressing a button must feel like pressing something. Without this, a click
   on a slow connection gives no feedback at all until the page reloads. */
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--brand-accent); color: #fff; }
.btn-primary:hover { background: #1668c4; }

.btn-ghost {
    background: transparent;
    color: #fff;
    border-color: rgba(255, 255, 255, .35);
}

.btn-block { width: 100%; }

/* ---------- Auth pages ---------- */

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: var(--space-4);
}

.auth-card {
    width: 100%;
    max-width: 26rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-6);
}

.auth-card h1 { margin-bottom: var(--space-4); }

.auth-alt { margin-top: var(--space-4); font-size: var(--text-sm); }

/* ---------- Wider screens ---------- */

@media (min-width: 700px) {
    .user-email { display: inline; }
    .grid { grid-template-columns: repeat(2, 1fr); }
    .usage-grid { grid-template-columns: repeat(2, 1fr); }
    .content { padding: var(--space-6); }
}

@media (min-width: 1000px) {
    .nav-toggle { display: none; }

    .layout {
        display: grid;
        grid-template-columns: 232px 1fr;
        align-items: start;
    }

    /* From here the sidebar is a permanent column, so the toggle state that
       shows/hides it on small screens must not apply any more. */
    .sidebar {
        display: block;
        border-bottom: 0;
        border-right: 1px solid var(--border);
        min-height: calc(100vh - 45px);
        position: sticky;
        top: 45px;
    }

    .grid { grid-template-columns: repeat(4, 1fr); }
    .two-col { grid-template-columns: 1fr 1fr; }
    .usage-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ---------- Phase 12.2: applications & deployments ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--gap);
}

.toolbar h2 { margin: 0; }

.inline-form { display: inline-flex; align-items: center; gap: var(--space-2); margin: 0; }

.app-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap);
}

.app-card { margin-bottom: 0; }
.app-card-name { font-size: var(--text-lg); margin: 0 0 var(--space-1); }
.app-card-name a { text-decoration: none; }
.app-card-runtime { color: var(--text-muted); font-size: var(--text-sm); margin: 0 0 var(--space-2); }

/* --- Application header + tabs --- */

.app-head { margin-bottom: var(--space-3); }
.app-name { font-size: var(--text-xl); margin: 0 0 var(--space-1); }

.app-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin: 0;
}

.tabs {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--gap);
}

.tab {
    padding: var(--space-2) var(--space-3);
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    min-height: 44px;
}

.tab { transition: color var(--transition-fast), border-color var(--transition-fast); }
.tab:hover { color: var(--text); }

.tab.is-active {
    color: var(--brand-accent);
    border-bottom-color: var(--brand-accent);
    font-weight: 600;
}

/* --- Action row --- */

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-danger:hover { background: #8f1e17; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card-danger { border-color: #f0c8c4; }
.card-danger h2 { color: var(--bad); }

/* --- Forms --- */

.form h2 { margin-top: var(--space-5); }
.form h2:first-of-type { margin-top: 0; }

.field select {
    width: 100%;
    padding: var(--space-3) var(--space-3);
    font-size: var(--text-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    min-height: 44px;
}

.field input[type="file"] { padding: var(--space-2) 0; }

.field-help { color: var(--text-muted); font-size: var(--text-sm); margin: var(--space-1) 0 0; }

.field-check { display: flex; align-items: center; gap: var(--space-2); }
.field-check label { margin: 0; font-weight: 400; }
.field-check input { width: auto; min-height: auto; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

/* --- Environment editor --- */

.env-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-2);
}

.env-row input[type="text"] {
    width: 100%;
    padding: var(--space-2) var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    min-height: 40px;
}

.env-key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.env-secret {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.env-secret input { width: auto; min-height: auto; }

/* --- Log viewer --- */

.log-view {
    background: #10161f;
    color: #d7e0ea;
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin: 0;
    max-height: 26rem;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: var(--text-xs);
    line-height: 1.5;
    /* Long lines wrap rather than forcing the page sideways on a phone. */
    white-space: pre-wrap;
    word-break: break-word;
}

.log-view:focus-visible { outline: 3px solid var(--brand-accent); outline-offset: 2px; }

/* --- Pager --- */

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin: var(--gap) 0;
}

.pager-status { color: var(--text-muted); font-size: var(--text-sm); }

@media (min-width: 700px) {
    .app-grid { grid-template-columns: repeat(2, 1fr); }
    .env-row { grid-template-columns: 1fr 1fr auto auto; align-items: center; }
}

@media (min-width: 1000px) {
    .app-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Phase 12.4: backups ---------- */

/* A SHA-256 is 64 characters — it must wrap rather than stretch the table. */
.checksum {
    font-size: var(--text-xs);
    word-break: break-all;
    display: inline-block;
    max-width: 22ch;
}

@media (min-width: 700px) {
    .checksum { max-width: none; }
}

/* ---------- Phase 12.6: account & security ---------- */

.scope-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-1);
    max-height: 18rem;
    overflow-y: auto;
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.scope-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    min-height: 32px;
}

.scope-option input { width: auto; min-height: auto; }

fieldset.field { border: 0; padding: 0; margin-bottom: var(--space-4); }
fieldset.field legend { font-size: var(--text-sm); font-weight: 600; padding: 0; margin-bottom: var(--space-1); }

@media (min-width: 700px) {
    .scope-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1000px) {
    .scope-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Phase 12.7: notifications ---------- */

.nav-count {
    display: inline-block;
    min-width: 1.4em;
    padding: 0 .4em;
    margin-left: .4em;
    border-radius: var(--radius-full);
    background: var(--brand-accent);
    color: #fff;
    font-size: var(--text-xs);
    font-weight: 700;
    text-align: center;
}

.nav-link.is-active .nav-count { background: #fff; color: var(--brand); }

.notification-list { list-style: none; margin: 0; padding: 0; }

.notification {
    padding: var(--space-3) 0 var(--space-3) var(--space-3);
    border-top: 1px solid var(--border);
    border-left: 3px solid transparent;
}

.notification:first-child { border-top: 0; }
.notification.is-unread { border-left-color: var(--brand-accent); background: #f7fbff; }

.notification-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}

.notification-title { font-weight: 600; margin: 0 0 var(--space-1); }

/* Event text can be long and can contain hostnames — wrap, never overflow. */
.notification-message {
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin: 0;
    overflow-wrap: anywhere;
}

.notification-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.notification-list-compact .notification { padding: var(--space-2) 0 var(--space-2) var(--space-2); }
