/* core.css
 *
 * Stable, shared frontend chrome extracted from styles.css as part of
 * Stage 0 of the frontend modularization plan
 * (docs/planning/frontend-modularization-and-csp-hardening-plan.md):
 * CSS variables, base layout/reset, header/nav, the tab framework, generic
 * buttons, generic modal chrome, and toast notifications.
 *
 * Load order matters: this file must be linked in index.html BEFORE
 * styles.css. Feature-specific overrides and responsive (@media)
 * adjustments for these same selectors still live in styles.css and rely
 * on that order to win the cascade where they apply -- they were
 * deliberately left in place rather than also moved here, to keep this
 * extraction mechanical and low-risk.
 */

/* Hidden-state convention: use the native `hidden` attribute (or toggle
 * this class) instead of inline style="display:none" going forward. The
 * !important guards against a lower-specificity display rule elsewhere in
 * the cascade accidentally winning.
 */
[hidden] {
    display: none !important;
}

:root {
    /* Style guide ramps and accents */
    --white: #FFFFFF;
    --cool-gray-9: #F6F6F6;
    --cool-gray-8: #E9E9EA;
    --cool-gray-7: #DBDBDD;
    --cool-gray-6: #C0C1C4;
    --cool-gray-5: #A4A6AA;
    --cool-gray-4: #777A80;
    --cool-gray-3: #4A4D55;
    --cool-gray-2: #35373B;
    --cool-gray-1: #1F2021;
    --black: #000000;

    --blue-green-9: #F2F9FB;
    --blue-green-8: #E0F0F6;
    --blue-green-7: #BFDFED;
    --blue-green-6: #7FC0DC;
    --blue-green-5: #40A1CB;
    --blue-green-4: #0081B9;
    --blue-green-3: #07638B;
    --blue-green-2: #0D445C;
    --blue-green-1: #14262E;

    --brand-blue: #004E9A;
    --brand-orange: #F07C0C;
    --brand-green: #5EB533;
    --brand-periwinkle: #6982BE;
    --brand-purple: #7B67A6;
    --brand-steel: #5D9BB4;

    --accent-blue: #087FBE;
    --accent-green: #549A71;
    --accent-yellow: #EDAF46;
    --accent-orange: #FF7944;
    --accent-red: #B22833;

    /* Semantic tokens */
    --primary-color: var(--blue-green-4);
    --primary-hover-overlay: linear-gradient(0deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.25) 100%);
    --primary-focus-ring: 0 0 0 4px rgba(0, 78, 154, 0.50);
    --secondary-color: var(--brand-orange);
    --secondary-hover: #B25F0F;
    --success-color: var(--accent-green);
    --success-bg: #EEF5F1;   /* guide Light Green Accent */
    --success-text: color-mix(in srgb, var(--success-color) 70%, var(--black));
    --danger-color: var(--accent-red);
    --danger-bg: #F7E9EB;    /* guide Light Red Accent */
    --danger-text: color-mix(in srgb, var(--danger-color) 70%, var(--black));
    --warning-color: var(--accent-yellow);
    --warning-bg: #FDF7EC;   /* guide Light Yellow Accent */
    --warning-text: color-mix(in srgb, var(--warning-color) 70%, var(--black));
    --info-color: var(--accent-blue);   /* 4th semantic role — badges using blue as an informational/neutral status, distinct from --primary-color's interactive-element role */
    --info-bg: #E6F2F8;      /* guide Light Blue Accent */
    --info-text: color-mix(in srgb, var(--info-color) 70%, var(--black));
    --primary-bg: color-mix(in srgb, var(--primary-color) 8%, var(--white));   /* generic "selected/active" tint paired with var(--primary-color) text/border */
    --bg-color: var(--cool-gray-9);
    --card-bg: var(--white);
    --text-primary: var(--cool-gray-1);
    --text-secondary: var(--cool-gray-3);
    --border-color: var(--cool-gray-7);
    --code-bg: var(--cool-gray-8);
    --button-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.10);
    --premium-color:  #9a6700;
    --premium-bg:     #fff7e6;
    --enterprise-color: #0f4c81;
    --enterprise-bg:    #eaf4ff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(0deg, var(--blue-green-7) 0%, var(--cool-gray-9) 100%);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 12px 16px;
}

header {
    background: linear-gradient(180deg, var(--brand-blue) 0%, var(--blue-green-3) 100%);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    box-shadow: var(--button-shadow);
    flex-shrink: 0;
    gap: 0.5rem;
}

.header-brand {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.7rem;
    flex: 1;
    min-width: 0;
}

.header-brand-logo {
    height: 36px;
    width: auto;
    max-width: 200px;
}

/* Hidden by default; phone.css reveals this at <=640px. Opens #nav-drawer, which replaces the
   tab bar as the main navigation only below that breakpoint -- the tab bar itself is untouched
   here and at every other width. */
.mobile-nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: white;
    cursor: pointer;
    padding: 0;
}

.mobile-nav-toggle svg {
    width: 22px;
    height: 22px;
}

/* #nav-drawer has no other CSS outside phone.css's <=640px block (it needs to stay
   render-able, not `hidden`, so the slide-in transform transition works there) -- without
   this base rule it falls back to a plain static, visible block at every other width. */
.nav-drawer {
    display: none;
}

/* device-detail header collapse/expand: phone-only, revealed in phone.css. Hidden here by
   the same base-rule pattern as .nav-drawer above -- without it these leak in at every
   other width, same bug class as the nav-drawer regression. */
.detail-summary-row {
    display: none;
}

.detail-menu-remove-btn {
    display: none;
    color: var(--danger-color);
}

.detail-last-seen-short {
    display: none;
}

/* Desktop-safe by construction, not by a phone-only override: these three wrappers stay
   `display:contents` at every width unless phone.css says otherwise, so their children
   (name/badges, Warranty/Docs, Location value+Change) always re-merge into the surrounding
   flex flow exactly as before -- no visual change on desktop regardless of what phone.css
   does with them for the collapsed/expanded phone layout. */
.detail-primary-row,
.detail-featured-row,
.detail-location-value-row {
    display: contents;
}

.header-title {
    font-size: 2.1rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    text-align: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

.header-auth-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
    flex: 1;
}

.modal-actions-left {
    justify-content: flex-start;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    padding: 0.35rem;
    border-radius: 10px;
    box-shadow: var(--button-shadow);
    flex-shrink: 0;
}

.tab-button {
    flex: 1;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.tab-button:hover {
    background: var(--primary-hover-overlay), var(--primary-color);
    color: var(--white);
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--button-shadow);
}

.container {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── End full-height chain ─────────────────────────────────────────────────── */

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.btn {
    padding: 8px 18px;
    border: 1px solid transparent;
    border-radius: 7px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
    box-shadow: var(--button-shadow);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    pointer-events: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover-overlay), var(--primary-color);
}

.btn-primary:focus-visible {
    outline: none;
    box-shadow: var(--primary-focus-ring);
}

.btn-primary:active {
    transform: translateY(1px);
    box-shadow: none;
}

.btn-primary:disabled {
    background: var(--cool-gray-6);
    border-color: var(--cool-gray-6);
    color: var(--cool-gray-3);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
    border: 2px solid var(--secondary-color);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
    border-color: var(--secondary-hover);
}

.btn-secondary:focus-visible {
    outline: none;
    box-shadow: var(--primary-focus-ring);
}

.btn-secondary:disabled {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.btn-ghost:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-ghost:disabled {
    background: transparent;
    color: var(--text-secondary);
}

.btn-icon {
    width: 30px;
    height: 30px;
    min-width: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

/* Touch-target sizing: (pointer: coarse) targets touch input specifically -- a touch-capable
   tablet or touchscreen laptop, not just narrow phone viewports -- rather than a layout
   breakpoint. Mouse/trackpad users keep the compact 30px sizing above. */
@media (pointer: coarse) {
    .btn-icon {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }
}

.btn-icon svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-color);
}

.btn-danger:disabled {
    background: var(--danger-color);
}

.btn-small {
    padding: 4px 12px 5px 12px;
    border-radius: 5px;
    font-size: 0.75rem;
}

.modal-box .message {
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

.btn-back {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.1rem 0.4rem;
    border-radius: 50%;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.btn-back:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* ── Confirm modal ─────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 23, 35, 0.46);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 1000;
}

.modal-box {
    background: var(--card-bg);
    border: 1px solid color-mix(in srgb, var(--primary-color) 20%, var(--border-color));
    border-top: 3px solid var(--primary-color);
    border-radius: 12px;
    padding: 1.75rem 2rem;
    max-width: 420px;
    width: 90%;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    margin: 0 auto;
    box-shadow: 0 20px 46px rgba(12, 30, 46, 0.28);
    position: relative;
}

.modal-title {
    font-size: 1.08rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.modal-body {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid color-mix(in srgb, var(--border-color) 82%, transparent);
}

.modal-box .form-group {
    margin-bottom: 1rem;
}

.modal-box .form-group:last-of-type {
    margin-bottom: 0;
}

.modal-box input[type="text"],
.modal-box input[type="number"],
.modal-box input[type="email"],
.modal-box input[type="password"],
.modal-box input[type="url"],
.modal-box input[type="tel"],
.modal-box input[type="date"],
.modal-box input[type="datetime-local"],
.modal-box textarea,
.modal-box select {
    border-width: 1px;
    border-radius: 8px;
    min-height: 38px;
    font-size: 0.94rem;
}

.modal-box textarea {
    min-height: 108px;
}

.modal-box input:focus,
.modal-box textarea:focus,
.modal-box select:focus {
    box-shadow: var(--primary-focus-ring);
}

.btn-spinner {
    display: inline-block;
    width: 0.85em;
    height: 0.85em;
    margin-right: 0.4em;
    vertical-align: -0.15em;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    opacity: 0.85;
    animation: spin 0.7s linear infinite;
}

/* ── Toast notifications ──────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 2000;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--danger-color);
    border-radius: 8px;
    padding: 0.7rem 1rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    font-size: 0.875rem;
    max-width: 360px;
    pointer-events: all;
    cursor: pointer;
    opacity: 0;
    transform: translateX(0.75rem);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.toast-visible {
    opacity: 1;
    transform: translateX(0);
}

.toast.toast-hiding {
    opacity: 0;
    transform: translateX(0.75rem);
}

.toast-icon {
    font-size: 1rem;
    line-height: 1.4;
    flex-shrink: 0;
}

.toast-message { flex: 1; line-height: 1.4; }

.toast.toast-error  { border-left-color: var(--danger-color); }

.toast.toast-warn   { border-left-color: var(--warning-color); }

.toast.toast-info   { border-left-color: var(--primary-color); }

.toast.toast-success{ border-left-color: var(--success-color); }

.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    cursor: default;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    top: 50%;
    left: 50%;
    margin: -7px 0 0 -7px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.55s linear infinite;
}

.btn-loading.btn-secondary::after,
.btn-loading.btn-ghost::after {
    border-color: color-mix(in srgb, var(--text-secondary) 40%, transparent);
    border-top-color: var(--text-secondary);
}
