/* ==========================================================================
   Infowise Master Dashboard Portal — design system v2
   infwise.com identity · deep navy glass · brand orange accent
   Barlow Condensed (display) · Montserrat (body)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens — palette extracted from infwise.com
   -------------------------------------------------------------------------- */
:root {
    /* Colour — deep navy surfaces, brand orange accent, cool neutral text */
    --bg:             #1a1a2e;
    --bg-elevated:    #22223a;
    --bg-light:       #2a2a45;
    --surface:        rgba(34, 34, 58, 0.55);
    --surface-solid:  #22223a;
    --border:         rgba(255, 255, 255, 0.08);
    --border-strong:  rgba(245, 130, 32, 0.38);

    --secondary:        #f58220;   /* brand orange — primary accent */
    --secondary-light:  #ff9a4d;
    --secondary-dark:   #d96d12;
    --secondary-tint:   rgba(245, 130, 32, 0.12);
    --secondary-ring:   rgba(245, 130, 32, 0.28);
    --accent:           #504c6a;   /* muted violet — secondary surfaces */

    --text:           #f0f0f0;
    --text-secondary: #a0a0b0;
    --text-muted:     #6b6b80;

    --success:        #2ecc71;
    --success-tint:   rgba(46, 204, 113, 0.10);
    --success-border: rgba(46, 204, 113, 0.30);

    --danger:         #e74c3c;
    --danger-tint:    rgba(231, 76, 60, 0.10);
    --danger-border:  rgba(231, 76, 60, 0.30);

    /* Spacing scale (4px base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-pill: 999px;

    /* Shadows — cool-tinted, layered */
    --shadow-card:
        0 1px 2px rgba(0, 0, 0, 0.35),
        0 12px 32px rgba(0, 0, 0, 0.40);
    --shadow-card-hover:
        0 2px 4px rgba(0, 0, 0, 0.35),
        0 20px 44px rgba(0, 0, 0, 0.50),
        0 0 0 1px rgba(245, 130, 32, 0.06),
        0 0 28px rgba(245, 130, 32, 0.10);

    /* Motion — buttery 200ms standard curve */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --speed: 200ms;

    /* Type — infwise.com pairing with system fallbacks */
    --font-display: 'Barlow Condensed', 'Arial Narrow', 'Helvetica Neue',
                    Arial, sans-serif;
    --font: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI',
            Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100svh;
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(245, 130, 32, 0.06), transparent 60%),
        radial-gradient(900px 500px at 10% 110%, rgba(80, 76, 106, 0.22), transparent 60%),
        var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection {
    background: rgba(245, 130, 32, 0.30);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* --------------------------------------------------------------------------
   3. Shared atoms
   -------------------------------------------------------------------------- */

/* Glass card primitive */
.card {
    background: var(--surface);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

/* Pill badge with a small brand-orange dot (infwise.com "CIVIL CONSTRUCTION") */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-4);
    background: rgba(34, 34, 58, 0.55);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--secondary);
    box-shadow: 0 0 8px rgba(245, 130, 32, 0.80);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition:
        background-color var(--speed) var(--ease),
        border-color var(--speed) var(--ease),
        color var(--speed) var(--ease),
        box-shadow var(--speed) var(--ease),
        transform var(--speed) var(--ease);
}

.btn-primary {
    width: 100%;
    padding: 13px var(--space-5);
    background: linear-gradient(180deg, var(--secondary-light), var(--secondary));
    color: #1a1a2e;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.22),
        0 6px 18px rgba(245, 130, 32, 0.22);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.28),
        0 10px 24px rgba(245, 130, 32, 0.32);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
    padding: 9px var(--space-4);
}

.btn-ghost:hover {
    color: var(--secondary-light);
    border-color: var(--border-strong);
    background: var(--secondary-tint);
}

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

/* Alerts — styled but unobtrusive */
.alert {
    margin: 0 0 var(--space-5);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.45;
    border: 1px solid;
}

.alert-error {
    color: #f2a79e;
    background: var(--danger-tint);
    border-color: var(--danger-border);
}

.alert-notice {
    color: var(--secondary-light);
    background: var(--secondary-tint);
    border-color: var(--border);
}

/* Brand lockup */
.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    text-align: center;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(160deg, var(--secondary-light), var(--secondary-dark));
    color: #1a1a2e;
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 700;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.25),
        0 6px 16px rgba(245, 130, 32, 0.25);
}

.brand-name {
    margin: var(--space-4) 0 0;
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text);
}

.brand-sub {
    margin: var(--space-1) 0 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.26em;
    text-transform: uppercase;
    color: var(--secondary);
}

/* Page footer */
.page-footer {
    padding: var(--space-6) var(--space-5);
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   4. Login page
   -------------------------------------------------------------------------- */
.page-login {
    display: grid;
    place-items: center;
    padding: var(--space-6) var(--space-4);
    overflow: hidden;
}

/* Slow-moving radial glow behind the card */
.glow {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(520px 420px at 50% 42%, rgba(245, 130, 32, 0.13), transparent 65%),
        radial-gradient(900px 700px at 20% 110%, rgba(80, 76, 106, 0.20), transparent 60%);
    animation: glow-drift 16s var(--ease) infinite alternate;
}

@keyframes glow-drift {
    from {
        transform: translate3d(-3%, -2%, 0) scale(1);
        opacity: 0.85;
    }
    to {
        transform: translate3d(3%, 2.5%, 0) scale(1.06);
        opacity: 1;
    }
}

.login-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(400px, 100%);
}

.login-card {
    width: 100%;
    padding: var(--space-7) var(--space-6) var(--space-6);
    animation: card-enter 480ms var(--ease) both;
}

@keyframes card-enter {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-card .brand {
    margin-bottom: var(--space-6);
}

.login-card .badge {
    margin-bottom: var(--space-4);
}

.login-card .alert {
    margin-bottom: var(--space-4);
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* Floating-label fields */
.field {
    position: relative;
}

.field input {
    width: 100%;
    padding: 22px var(--space-4) 8px;
    background: rgba(26, 26, 46, 0.55);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font: inherit;
    font-size: 15px;
    transition:
        border-color var(--speed) var(--ease),
        box-shadow var(--speed) var(--ease),
        background-color var(--speed) var(--ease);
}

.field input:hover {
    border-color: rgba(255, 255, 255, 0.16);
}

.field input:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px var(--secondary-ring);
    background: rgba(26, 26, 46, 0.75);
}

.field label {
    position: absolute;
    left: var(--space-4);
    top: 16px;
    color: var(--text-secondary);
    font-size: 15px;
    pointer-events: none;
    transform-origin: left top;
    transition:
        transform var(--speed) var(--ease),
        color var(--speed) var(--ease);
}

.field input:focus + label,
.field input:not(:placeholder-shown) + label {
    transform: translateY(-9px) scale(0.78);
    color: var(--secondary-light);
}

/* --------------------------------------------------------------------------
   5. Dashboard
   -------------------------------------------------------------------------- */

/* Sticky top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(26, 26, 46, 0.72);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    max-width: 1120px;
    margin: 0 auto;
    padding: var(--space-3) var(--space-5);
}

.brand-topbar {
    flex-direction: row;
    gap: var(--space-3);
    text-align: left;
}

.brand-topbar .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 20px;
    border-radius: 9px;
}

.brand-topbar .brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-topbar .brand-name {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
}

.brand-topbar .brand-sub {
    margin: 0;
    font-size: 9px;
    letter-spacing: 0.20em;
}

.user-area {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 5px var(--space-3) 5px 5px;
    background: var(--secondary-tint);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(160deg, var(--secondary-light), var(--secondary-dark));
    color: #1a1a2e;
    font-size: 13px;
    font-weight: 700;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

/* Main content */
.dash-main {
    max-width: 1120px;
    margin: 0 auto;
    padding: var(--space-7) var(--space-5) var(--space-8);
}

/* Hero strip */
.hero {
    margin-bottom: var(--space-6);
    animation: card-enter 420ms var(--ease) both;
}

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

.hero-title {
    margin: 0;
    font-size: clamp(30px, 4.4vw, 44px);
    font-weight: 700;
    letter-spacing: 0.01em;
    text-transform: uppercase;
}

.hero-user {
    color: var(--secondary-light);
}

.hero-meta {
    margin: var(--space-2) 0 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.hero-status {
    margin: var(--space-3) 0 0;
}

/* Status pill — green when all up, orange/red when attention is needed */
.pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 7px var(--space-4);
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid;
}

.pill-ok {
    color: #7be2a8;
    background: var(--success-tint);
    border-color: var(--success-border);
}

.pill-bad {
    color: var(--secondary-light);
    background: rgba(245, 130, 32, 0.12);
    border-color: var(--border-strong);
}

/* Section headings */
.dash-section {
    margin-top: var(--space-7);
}

.dash-section:first-of-type {
    margin-top: 0;
}

.section-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.section-title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
}

.section-title::after {
    content: '';
    display: block;
    width: 36px;
    height: 3px;
    margin-top: var(--space-1);
    border-radius: 2px;
    background: linear-gradient(90deg, var(--secondary), transparent);
}

.status-stale {
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary-light);
    background: var(--secondary-tint);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 3px var(--space-3);
}

/* App card grid — responsive auto-fit */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-5);
}

.app-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-5);
    /* Staggered fade-in on load (delay derived from the --i custom prop) */
    animation: card-enter 460ms var(--ease) both;
    animation-delay: calc(var(--i, 0) * 70ms);
    transition:
        transform var(--speed) var(--ease),
        border-color var(--speed) var(--ease),
        box-shadow var(--speed) var(--ease),
        background-color var(--speed) var(--ease);
}

.app-card:hover {
    transform: translateY(-4px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-card-hover);
}

.app-card:focus-visible {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px var(--secondary-ring);
}

/* Orange-tinted icon tile */
.icon-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--secondary-tint);
    border: 1px solid var(--border);
    color: var(--secondary);
    transition:
        color var(--speed) var(--ease),
        background-color var(--speed) var(--ease),
        border-color var(--speed) var(--ease);
}

.app-card:hover .icon-tile {
    color: var(--secondary-light);
    background: rgba(245, 130, 32, 0.18);
    border-color: var(--border-strong);
}

.icon-tile svg {
    width: 24px;
    height: 24px;
}

.app-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
}

.app-name {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

.app-desc {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* "Open →" affordance */
.app-open {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: var(--space-2);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    transition: color var(--speed) var(--ease);
}

.app-open svg {
    width: 15px;
    height: 15px;
    transition: transform var(--speed) var(--ease);
}

.app-card:hover .app-open {
    color: var(--secondary-light);
}

.app-card:hover .app-open svg {
    transform: translateX(3px);
}

.empty-state {
    padding: var(--space-6);
    text-align: center;
    color: var(--text-secondary);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
}

/* --------------------------------------------------------------------------
   6. Server status tiles
   -------------------------------------------------------------------------- */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-4);
}

.svc-tile {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    transition:
        border-color var(--speed) var(--ease),
        background-color var(--speed) var(--ease);
}

.svc-tile.tile-down {
    border-color: var(--danger-border);
    background: linear-gradient(180deg, var(--danger-tint), var(--surface));
}

.svc-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.svc-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 13px;
}

/* Pulsing status dot */
.status-dot {
    width: 10px;
    height: 10px;
    flex: none;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.is-up {
    background: var(--success);
    animation: pulse-up 2s var(--ease) infinite;
}

.status-dot.is-down {
    background: var(--danger);
    animation: pulse-down 2s var(--ease) infinite;
}

@keyframes pulse-up {
    0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.45); }
    70%  { box-shadow: 0 0 0 7px rgba(46, 204, 113, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

@keyframes pulse-down {
    0%   { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.45); }
    70%  { box-shadow: 0 0 0 7px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

.svc-state {
    font-weight: 600;
}

.svc-state.is-up {
    color: var(--success);
}

.svc-state.is-down {
    color: var(--danger);
}

.svc-latency {
    margin-left: auto;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   7. Resources panel — meters + uptime chip
   -------------------------------------------------------------------------- */
.resources-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding: var(--space-5);
}

.meter-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.meter-label {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.meter-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

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

.meter-fill {
    display: block;
    height: 100%;
    border-radius: var(--radius-pill);
    background: linear-gradient(90deg, var(--secondary-dark), var(--secondary), var(--secondary-light));
    transition: width 600ms var(--ease);
}

.meter-fill.meter-hot {
    background: linear-gradient(90deg, var(--secondary-dark), var(--danger));
}

.resources-footer {
    display: flex;
    justify-content: flex-end;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-4);
    border-radius: var(--radius-pill);
    background: var(--secondary-tint);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.chip strong {
    color: var(--secondary-light);
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
}

/* --------------------------------------------------------------------------
   8. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .card-grid,
    .status-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .topbar-inner {
        padding: var(--space-3) var(--space-4);
    }

    .user-name {
        display: none; /* avatar alone carries identity on small screens */
    }

    .dash-main {
        padding: var(--space-6) var(--space-4) var(--space-7);
    }

    .login-card {
        padding: var(--space-6) var(--space-5);
    }
}

/* --------------------------------------------------------------------------
   9. Reduced motion — honour the OS preference
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .glow {
        animation: none;
    }
}
