/* =========================================================
   GLOBAL / BASE STYLES (Light Mode Default)
   ========================================================= */
:root {
    --bg-page: #f8fafc;
    --bg-panel: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-input: #ffffff;

    --border: #e2e8f0;
    --border-hover: #cbd5e1;

    --text: #0f172a;
    --text-soft: #475569;
    --muted: #64748b;

    --accent: #f97316;
    --accent-hover: #ea580c;
    --accent-soft: rgba(249, 115, 22, 0.12);

    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.10);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.10);
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.10);
    --info: #0284c7;
    --info-bg: rgba(2, 132, 199, 0.10);

    /* Contextual Variables */
    --nav-hover: rgba(0, 0, 0, 0.05);
    --code-text: #c2410c;
    --code-bg: #ffedd5;
    --pre-text: #334155;
    --pre-bg: #f1f5f9;
    --keybox-text: #c2410c;
    --keybox-bg: #ffedd5;
    --unknown-bg: rgba(0, 0, 0, 0.05);
    --btn-text: #ffffff;

    --radius: 8px;
    --radius-small: 6px;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
}

/* =========================================================
   DARK MODE (OS System Preference)
   ========================================================= */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-page: #090a0c;
        --bg-panel: #111317;
        --bg-card: #15181d;
        --bg-card-hover: #191d23;
        --bg-input: #0b0d10;

        --border: #23272e;
        --border-hover: #343a44;

        --text: #ecedee;
        --text-soft: #a1a7b0;
        --muted: #6e7682;

        --accent: #ff9800;
        --accent-hover: #ffab2e;
        --accent-soft: rgba(255, 152, 0, 0.12);

        --success: #49c779;
        --success-bg: rgba(73, 199, 121, 0.10);
        --warning: #ffb84d;
        --warning-bg: rgba(255, 184, 77, 0.10);
        --danger: #ff6b6b;
        --danger-bg: rgba(255, 107, 107, 0.10);
        --info: #6da9ff;
        --info-bg: rgba(109, 169, 255, 0.10);

        /* Contextual Variables */
        --nav-hover: rgba(255, 255, 255, 0.05);
        --code-text: #e5a854;
        --code-bg: #15181c;
        --pre-text: #c2c7cf;
        --pre-bg: #0d0f12;
        --keybox-text: #ffb85c;
        --keybox-bg: #090c10;
        --unknown-bg: rgba(255, 255, 255, 0.05);
        --btn-text: #000000;

        --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
        --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
    }
}

/* =========================================================
   RESET & TYPOGRAPHY
   ========================================================= */
* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-page);
    color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

a {
    color: inherit;
    text-decoration: none;
}

.muted {
    color: var(--muted);
}

/* =========================================================
   TOP NAVIGATION
   ========================================================= */
.top {
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 25px;
    padding: 0 28px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.brand {
    color: var(--accent);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.top nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.top nav a {
    padding: 8px 14px;
    color: var(--text-soft);
    border-radius: var(--radius-small);
    font-size: 13px;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
}

.top nav a:hover {
    color: var(--text);
    background: var(--nav-hover);
}

.top nav a.active {
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
}

/* =========================================================
   MAIN CONTENT & LAYOUT
   ========================================================= */
.wrap {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 28px;
}

.hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 24px;
}

.hero h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }

/* =========================================================
   GENERIC FORM CONTROLS
   ========================================================= */
input, select, textarea {
    width: 100%;
    padding: 10px 14px;
    color: var(--text);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    outline: none;
    font: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:hover, select:hover, textarea:hover {
    border-color: var(--border-hover);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

input::placeholder, textarea::placeholder {
    color: #4b525d;
}

input:disabled {
    color: var(--muted);
    background: var(--bg-page);
    cursor: not-allowed;
}

label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 500;
}

/* =========================================================
   CODE & API KEYS
   ========================================================= */
code {
    padding: 3px 6px;
    color: var(--code-text);
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

pre {
    margin: 14px 0;
    padding: 16px;
    color: var(--pre-text);
    background: var(--pre-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 13px;
    line-height: 1.5;
    overflow-x: auto;
}

.keybox {
    display: block;
    margin: 12px 0;
    padding: 15px;
    color: var(--keybox-text);
    background: var(--keybox-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    font-family: ui-monospace, SFMono-Regular, monospace;
    word-break: break-all;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 18px;
    background: var(--accent);
    color: var(--btn-text) !important;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn:hover {
    background: var(--accent-hover);
}

.btn:active {
    transform: scale(0.98);
}

.btn.secondary {
    background: var(--bg-card);
    color: var(--text) !important;
    border-color: var(--border);
}

.btn.secondary:hover {
    background: var(--bg-card-hover);
}

.btn.small {
    min-height: 32px;
    padding: 6px 12px;
    font-size: 12px;
}

/* =========================================================
   PUBLIC LANDING PAGE
   ========================================================= */
.landing-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.7fr);
    gap: 40px;
    align-items: center;
    padding: 40px;
    margin-bottom: 28px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.landing-hero-content h1 {
    max-width: 800px;
    margin: 12px 0 16px;
    font-size: 32px;
    line-height: 1.15;
    letter-spacing: -0.02em;
}

.landing-eyebrow {
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.landing-lead {
    max-width: 720px;
    margin: 0;
    color: var(--text-soft);
    font-size: 16px;
    line-height: 1.6;
}

.landing-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 24px;
}

.landing-example {
    padding: 24px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    text-align: center;
}

.landing-example code {
    display: block;
    margin-top: 8px;
    padding: 10px;
    font-size: 13px;
}

.landing-example-label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.landing-arrow {
    margin: 12px 0;
    color: var(--muted);
    font-size: 18px;
}

.landing-section {
    margin-bottom: 24px;
    padding: 40px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.section-heading {
    margin-bottom: 30px;
}

.section-heading h2 {
    margin: 8px 0 6px;
    font-size: 22px;
    font-weight: 600;
}

.landing-info-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.landing-info-card {
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}

.landing-info-card h3 {
    margin: 12px 0 8px;
    font-size: 15px;
    font-weight: 600;
}

.landing-info-card p {
    margin: 0;
    color: var(--text-soft);
    font-size: 13px;
    line-height: 1.6;
}

.landing-number {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
}

.howto-list {
    display: grid;
    gap: 12px;
}

.howto-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}

.howto-step {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    color: var(--btn-text);
    background: var(--accent);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
}

.howto-item h3 {
    margin: 0 0 4px;
    font-size: 15px;
}

.howto-item p {
    margin: 0;
    color: var(--text-soft);
    font-size: 13px;
}

.landing-code pre {
    margin: 0;
}

.plan-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.plan-card {
    padding: 30px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}

.plan-card.featured {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-soft);
}

.plan-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.plan-card-header h3 {
    margin: 0;
    font-size: 20px;
}

.plan-card ul {
    margin: 24px 0;
    padding-left: 18px;
    color: var(--text-soft);
    font-size: 13px;
}

.plan-card li {
    margin: 10px 0;
}

.landing-cta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 25px;
    padding: 40px;
    margin-bottom: 28px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.landing-cta h2 {
    margin: 0 0 6px;
    font-size: 20px;
}

/* =========================================================
   LOGIN / AUTHENTICATION
   ========================================================= */
.auth-shell {
    min-height: calc(100vh - 140px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 20px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 40px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.auth-brandmark {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    color: var(--accent);
    font-weight: 700;
}

.auth-header h1 {
    margin: 0 0 8px;
    font-size: 24px;
}

.auth-header h2 {
    margin: 0 0 8px;
}

.auth-header p {
    margin: 0 0 24px;
    color: var(--text-soft);
}

.auth-field {
    margin-bottom: 16px;
}

.auth-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.auth-input-wrap input {
    padding-left: 40px;
}

.auth-input-icon {
    position: absolute;
    left: 14px;
    color: var(--muted);
    font-size: 14px;
}

.auth-submit {
    width: 100%;
    margin-top: 8px;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 24px 0;
    color: var(--muted);
    font-size: 12px;
}

.auth-divider::before, .auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-register {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* =========================================================
   DASHBOARD COMPONENTS
   ========================================================= */
.dashboard-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    padding: 24px 28px;
    margin-bottom: 24px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.dashboard-hero h1 {
    margin: 0 0 4px;
    font-size: 22px;
}

.dashboard-hero h2 {
    margin: 0 0 4px;
}

.plan-badge {
    display: inline-flex;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.plan-badge.free {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-soft);
}

.plan-badge.premium {
    background: var(--accent-soft);
    border: 1px solid rgba(255,152,0,0.3);
    color: var(--accent);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.dashboard-card {
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}

.dashboard-card .label {
    margin-bottom: 8px;
    color: var(--text-soft);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.dashboard-card .value {
    font-size: 26px;
    font-weight: 600;
    line-height: 1.2;
}

.panel {
    margin-bottom: 24px;
    padding: 28px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.panel h2 {
    margin: 0 0 20px;
    font-size: 18px;
}

.panel h3 {
    margin: 0;
}

/* =========================================================
   CREATE HOST FORM
   ========================================================= */
.create-grid {
    display: grid;
    grid-template-columns: minmax(180px, .9fr) minmax(300px, 1.7fr) minmax(160px, .7fr) auto;
    gap: 16px;
    align-items: end;
}

.hostname-input {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.hostname-input:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.hostname-input input {
    flex: 1;
    border: 0;
    background: transparent;
    box-shadow: none !important;
}

.hostname-suffix {
    padding-right: 12px;
    color: #747d89;
    font-family: monospace;
    font-size: 12px;
}

/* =========================================================
   HOST LIST & CARDS
   ========================================================= */
.host-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.host-card {
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}

.host-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.host-name {
    font-size: 16px;
    font-weight: 600;
}

.host-fqdn {
    margin-top: 4px;
    color: var(--muted);
    font-family: monospace;
    font-size: 12px;
}

.status {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid transparent;
}

.status.online { color: var(--success); background: var(--success-bg); border-color: rgba(73,199,121,0.2); }
.status.stale { color: var(--warning); background: var(--warning-bg); border-color: rgba(255,184,77,0.2); }
.status.offline { color: var(--danger); background: var(--danger-bg); border-color: rgba(255,107,107,0.2); }
.status.unknown { color: var(--muted); background: var(--unknown-bg); border-color: var(--border); }

.host-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.host-info-item {
    padding: 10px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.host-info-item .label {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
}

.host-info-item .value {
    font-size: 12px;
    font-weight: 500;
}

.host-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.host-meta {
    color: var(--muted);
    font-size: 11px;
}

/* =========================================================
   TABLES & MISC
   ========================================================= */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

tr:last-child td {
    border-bottom: none;
}

.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--muted);
}

.flash-message {
    padding: 14px 16px;
    margin-bottom: 20px;
    border-radius: var(--radius-small);
    border: 1px solid;
    font-size: 13px;
    font-weight: 500;
}

.flash-message.error { background: var(--danger-bg); border-color: rgba(255,107,107,0.3); color: #dc2626; }
.flash-message.success { background: var(--success-bg); border-color: rgba(73,199,121,0.3); color: #16a34a; }

@media (prefers-color-scheme: dark) {
    .flash-message.error { color: #ff9a9a; }
    .flash-message.success { color: #83e5a7; }
}

.progress {
    width: 100%;
    height: 6px;
    margin-top: 12px;
    background: var(--bg-page);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
}

/* =========================================================
   RESPONSIVE DESIGN & MOBILE OPTIMIZATIONS
   ========================================================= */
@media (max-width: 900px) {
    .landing-hero { grid-template-columns: 1fr; }
    .landing-info-grid, .plan-grid { grid-template-columns: 1fr; }
    .create-grid, .two { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    /* Mobile Touch & iOS Zoom Fixes */
    input, select, textarea {
        font-size: 16px !important; /* Stops iOS from auto-zooming */
        min-height: 44px; /* Apple's minimum touch target */
    }
    
    .btn, button[type="submit"] {
        min-height: 48px;
        width: 100%;
    }

    /* Swipeable Mobile Navigation Bar */
    .top {
        flex-direction: column;
        align-items: flex-start;
        padding: 16px;
        gap: 16px;
    }
    
    .top nav {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; 
        scrollbar-width: none; 
        -ms-overflow-style: none;
        padding-bottom: 4px;
    }
    
    .top nav::-webkit-scrollbar { display: none; }
    
    .top nav a {
        background: var(--bg-card);
        border: 1px solid var(--border);
        padding: 10px 14px;
        white-space: nowrap;
    }

    /* Full-screen auth cards on mobile */
    .auth-card {
        border-radius: 0;
        border-left: none;
        border-right: none;
        height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    body:has(.auth-card) { align-items: flex-start; }
    
    /* Scrollable tables so they don't break the page width */
    table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 600px) {
    .wrap { padding: 24px 16px; }
    .landing-section, .panel, .landing-hero, .landing-cta { padding: 24px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    
    /* Force side-by-side grids to stack vertically */
    .create-grid, .host-grid, .two { 
        display: flex !important; 
        flex-direction: column !important; 
        gap: 16px !important;
    }
    
    .landing-actions { flex-direction: column; }
    .landing-actions .btn { width: 100%; }
    
    /* Make inline forms stack */
    form[action="diagnostics.php"] > div { max-width: 100% !important; }
}