/* ==========================================================================
   Design tokens — light-mode counterpart of hejduk.se
   Same monospace stack, orange accent, and hairline-border language as the
   parent site; token names (--bg, --text, --muted, --dim, --accent, --border)
   deliberately mirror hejduk.se's.
   ========================================================================== */
:root {
    color-scheme: light;

    --bg:      #F5F5F3;
    --surface: #FFFFFF;
    --text:    #1A1A1A;
    --muted:   #494944;
    --dim:     #6C6C66;
    --border:  #E3E2DE;

    /* Orange, three roles: solid CTA fill, readable ink on light bg, decoration */
    --cta:              #FF6B35;
    --cta-hover:        #E85E28;
    --accent:           #E85E28;
    --accent-ink:       #C2410C;
    --accent-ink-hover: #9A3412;

    --danger:  #B91C1C;
    --success: #15803D;
    --warning: #92400E;

    --row-hover: #F7F6F3;

    /* Record-type chip inks (all readable on white) */
    --rr-a:     #1D4ED8;
    --rr-aaaa:  #6D28D9;
    --rr-mx:    #047857;
    --rr-cname: #92400E;
    --rr-txt:   #52525B;
    --rr-ns:    #0F766E;
    --rr-srv:   #BE185D;
    --rr-soa:   #475569;
    --rr-ptr:   #6D28D9;
    --rr-caa:   #0369A1;

    --nav-height: 54px;
    --container-width: 1080px;

    --mono: "SF Mono", "Cascadia Code", "JetBrains Mono", "Fira Code", "Consolas", "Courier New", monospace;
    --font-mono: var(--mono);
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a {
    color: var(--accent-ink);
    text-decoration: none;
    transition: color 0.12s;
}

a:hover {
    color: var(--accent-ink-hover);
    text-decoration: underline;
}

::selection {
    background: rgba(255, 107, 53, 0.25);
}

input, select, textarea, button {
    accent-color: var(--cta);
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1 { font-size: 1.4rem;  font-weight: 500; letter-spacing: -0.01em; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; font-weight: 500; letter-spacing: -0.01em; margin-bottom: 0.75rem; }
h3 { font-size: 1rem;    font-weight: 500; margin-bottom: 0.5rem; }

.text-muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.small { font-size: 0.82rem; }
.mt-2 { margin-top: 0.75rem; }
.inline { display: inline; }

/* ==========================================================================
   Layout
   ========================================================================== */
.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
}

.container-narrow {
    max-width: 500px;
}

/* Page header: title left, actions right */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin-bottom: 0;
}

/* Breadcrumb — the dim label above a page title */
.breadcrumb {
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    color: var(--dim);
    margin-bottom: 0.5rem;
}

.breadcrumb a {
    color: var(--dim);
}

.breadcrumb a:hover {
    color: var(--accent-ink);
    text-decoration: none;
}

.breadcrumb .separator {
    margin: 0 0.4rem;
    color: var(--border);
}

/* ==========================================================================
   Navbar
   ========================================================================== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(245, 245, 243, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    height: var(--nav-height);
    display: flex;
    align-items: center;
    margin-bottom: 2rem;
}

.navbar-inner {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 1.5rem;
}

.nav-brand {
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: var(--text);
    text-decoration: none;
    margin-right: 2.5rem;
    white-space: nowrap;
}

.nav-brand:hover {
    color: var(--text);
    text-decoration: none;
}

.nav-brand .brand-dns {
    color: var(--accent-ink);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex: 1;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    letter-spacing: 0.03em;
    color: var(--muted);
    text-decoration: none;
    padding: 0.5rem 0.1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: color 0.12s;
}

.nav-link:hover,
.nav-link:focus-visible {
    color: var(--text);
    background: none;
    text-decoration: none;
}

/* Current organization — highlighted like nav-dns on hejduk.se */
.nav-link-org {
    color: var(--accent-ink);
}

.nav-link-org:hover,
.nav-link-org:focus-visible {
    color: var(--accent-ink-hover);
}

.nav-link svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.nav-spacer {
    flex: 1;
}

/* Hamburger */
.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0.25rem;
}

.hamburger svg {
    width: 24px;
    height: 24px;
}

/* ==========================================================================
   Cards — flat surfaces, hairline borders, no shadows
   ========================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.76rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--dim);
}

.card-body {
    padding: 1.25rem;
}

/* ==========================================================================
   Tables
   ========================================================================== */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table thead th {
    position: sticky;
    top: var(--nav-height);
    background: var(--surface);
    font-weight: 500;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--dim);
    z-index: 1;
}

.table tbody tr:hover {
    background: var(--row-hover);
}

/* Card-mounted tables sit flush against the card border */
.card > .table thead th {
    border-top: none;
}

/* ==========================================================================
   Badges — hejduk.se's bordered RR chip, carried into the app
   ========================================================================== */
.badge {
    display: inline-block;
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0.15em 0.6em;
    color: var(--dim);
    background: transparent;
    border: 1px solid currentColor;
    border-color: color-mix(in srgb, currentColor 35%, transparent);
    white-space: nowrap;
}

/* Record types */
.badge-A,     .badge-a     { color: var(--rr-a); }
.badge-AAAA,  .badge-aaaa  { color: var(--rr-aaaa); }
.badge-MX,    .badge-mx    { color: var(--rr-mx); }
.badge-CNAME, .badge-cname { color: var(--rr-cname); }
.badge-ALIAS, .badge-alias { color: var(--rr-cname); }
.badge-TXT,   .badge-txt   { color: var(--rr-txt); }
.badge-NS,    .badge-ns    { color: var(--rr-ns); }
.badge-SRV,   .badge-srv   { color: var(--rr-srv); }
.badge-SOA,   .badge-soa   { color: var(--rr-soa); }
.badge-PTR,   .badge-ptr   { color: var(--rr-ptr); }
.badge-CAA,   .badge-caa   { color: var(--rr-caa); }

/* Zone plans */
.badge-standard { color: var(--muted); }
.badge-premium  { color: var(--accent-ink); }

/* Status */
.badge-success { color: var(--success); }
.badge-warning { color: var(--warning); }
.badge-info    { color: var(--rr-a); }

/* Role badge (org picker) */
.role-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0.15em 0.6em;
    color: var(--dim);
    border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
    margin-left: 0.5rem;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-group {
    margin-bottom: 1rem;
}

.form-group > label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--muted);
}

/* Field captions (not labels wrapping a checkbox/radio) get the
   uppercase micro-label treatment */
.form-group > label:not(:has(input)) {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.form-group input,
.form-control {
    width: 100%;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--border);
    font-size: 0.92rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border-radius: 0;
    transition: border-color 0.12s;
}

.form-group input:focus,
.form-control:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group input[type="radio"],
.form-group input[type="checkbox"] {
    width: auto;
}

.form-control-sm {
    padding: 0.3rem 0.5rem;
    font-size: 0.86rem;
}

select.form-control {
    appearance: auto;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.form-row > .form-control {
    width: auto;
    flex: 1;
    min-width: 150px;
}

.form-row > select.form-control {
    flex: 0 1 auto;
    min-width: 110px;
}

.form-group-grow {
    flex: 1;
    min-width: 150px;
}

.form-group-btn {
    flex-shrink: 0;
    padding-top: 1.45rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.form-hint {
    display: block;
    color: var(--dim);
    font-size: 0.8rem;
    margin-top: 0.3rem;
}

.form-hint-mono {
    font-family: var(--mono);
}

/* Radio plan picker */
.radio-group {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.radio-option {
    display: block;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.12s;
}

.radio-option:hover {
    border-color: var(--accent);
}

.radio-option input[type="radio"] {
    margin-right: 0.5rem;
}

/* ==========================================================================
   Buttons — flat, square, mono; solid orange for the primary action
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5em 1.1em;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    font-family: inherit;
    line-height: 1.5;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--surface);
    text-decoration: none;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--cta);
    border-color: var(--cta);
    color: #111111;
}

.btn-primary:hover {
    background: var(--cta-hover);
    border-color: var(--cta-hover);
    color: #111111;
}

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

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

.btn-danger {
    background: var(--surface);
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

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

.btn-sm {
    padding: 0.3em 0.75em;
    font-size: 0.82rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-group form {
    display: flex;
}

/* ==========================================================================
   Flash / alerts — flat strips, hairline border in the status hue
   ========================================================================== */
.flash,
.alert,
.error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    background: var(--surface);
    border: 1px solid color-mix(in srgb, currentColor 40%, transparent);
}

/* Bare .flash is the success case (see base.html) */
.flash,
.flash-success,
.alert-success {
    color: var(--success);
}

.flash svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.flash span {
    flex: 1;
}

.flash-dismiss {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.125rem;
    opacity: 0.6;
    color: inherit;
}

.flash-dismiss:hover {
    opacity: 1;
}

.flash-error,
.alert-error,
.error {
    color: var(--danger);
}

.flash-warning {
    color: var(--warning);
}

/* Element cleared via JS by setting className="" */
#record-form-error:empty {
    display: none;
}

/* ==========================================================================
   Empty states
   ========================================================================== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--dim);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state p {
    margin-bottom: 1rem;
}

/* ==========================================================================
   Icons
   ========================================================================== */
svg {
    vertical-align: middle;
}

/* ==========================================================================
   Records (zone detail)
   ========================================================================== */
.records-table .actions-col {
    width: 1%;
    white-space: nowrap;
}

.record-content {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-family: var(--mono);
    font-size: 0.9rem;
    word-break: break-all;
}

.record-content span {
    flex: 1;
}

.record-content .btn {
    margin-bottom: 0.3rem;
}

.inline-form {
    display: inline;
}

.record-disabled {
    opacity: 0.5;
    text-decoration: line-through;
}

.record-edit-row .form-control {
    margin-bottom: 0.25rem;
}

.record-edit-row .form-control:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Admin dashboard
   ========================================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1rem 1.25rem;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 400;
    line-height: 1.2;
    color: var(--text);
}

.stat-label {
    font-size: 0.74rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--dim);
    margin-top: 0.35rem;
}

.admin-nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Definition lists (admin billing details) */
dl dt {
    font-size: 0.74rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--dim);
}

dl dd {
    margin: 0 0 0.75rem;
    font-size: 0.92rem;
}

/* ==========================================================================
   htmx loading states
   ========================================================================== */
.htmx-request {
    opacity: 0.6;
    pointer-events: none;
    transition: opacity 200ms;
}

.htmx-settling {
    opacity: 1;
}

/* ==========================================================================
   Focus indicators
   ========================================================================== */
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================================================
   Page-load animation (from hejduk.se) — `backwards` fill only, so no
   transform lingers on ancestors of position:sticky table headers
   ========================================================================== */
@media (prefers-reduced-motion: no-preference) {
    @keyframes arise {
        from { opacity: 0; transform: translateY(6px); }
    }

    main > *:nth-child(-n+4) {
        animation: arise 0.35s ease backwards;
    }
    main > *:nth-child(1) { animation-delay: 0.05s; }
    main > *:nth-child(2) { animation-delay: 0.12s; }
    main > *:nth-child(3) { animation-delay: 0.19s; }
    main > *:nth-child(4) { animation-delay: 0.26s; }
}

/* ==========================================================================
   Responsive (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
    .hamburger {
        display: block;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        padding: 0.5rem 0;
        gap: 0;
        z-index: 99;
    }

    .nav-links[data-open] {
        display: flex;
    }

    .nav-link {
        padding: 0.75rem 1.5rem;
        width: 100%;
    }

    .nav-spacer {
        display: none;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .form-row {
        flex-direction: column;
    }

    .form-row > .form-control,
    .form-row > select.form-control {
        width: 100%;
    }

    /* Wide tables scroll inside their card; sticky headers yield on mobile */
    .card {
        overflow-x: auto;
    }

    .table thead th {
        position: static;
    }
}

/* ==========================================================================
   Auth pages (login, magic-link, org picker)
   ========================================================================== */
.auth-container {
    max-width: 440px;
    margin: 4rem auto;
}

.auth-container h1 {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
}

.auth-container .auth-sub {
    color: var(--muted);
    font-size: 0.92rem;
    margin-bottom: 1.5rem;
}

.auth-container p {
    margin-bottom: 1rem;
}

/* Org option — list item in the org-picker */
.org-option {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
    background: var(--surface);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.12s;
}

.org-option:hover {
    border-color: var(--accent);
}

.org-option input[type="radio"] {
    margin-right: 0.75rem;
}

.org-name {
    font-weight: 500;
    font-size: 0.95rem;
}
