/* ============================================================
   Folla Monitor — style.css
   Shared stylesheet for index.php and admin.php
   ============================================================ */

/* --- Variables --- */
:root {
    --bg:        #0d0f0e;
    --bg2:       #141716;
    --bg3:       #1c1f1d;
    --border:    #2a2e2b;
    --text:      #c8cfc9;
    --muted:     #5a6459;
    --green:     #4ade80;
    --green-dim: #1a3d25;
    --red:       #f87171;
    --red-dim:   #3d1a1a;
    --amber:     #fbbf24;
    --amber-dim: #3d2f0a;
    --blue:      #60a5fa;
    --mono:      'IBM Plex Mono', monospace;
    --sans:      'IBM Plex Sans', sans-serif;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* ============================================================
   Layout
   ============================================================ */

header {
    border-bottom: 1px solid var(--border);
    padding: 16px 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.logo {
    font-family: var(--mono);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.05em;
    color: var(--green);
    text-decoration: none;
}
.logo span { color: var(--muted); font-weight: 400; }
.logo:hover { text-decoration: none; }

.header-time {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
}

/* Navigation (admin) */
nav { display: flex; gap: 4px; align-items: center; }

.nav-link {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 3px;
    border: 1px solid transparent;
    text-decoration: none;
}
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--green); border-color: var(--border); background: var(--bg2); }

.nav-sep { color: var(--border); margin: 0 4px; }

.btn-logout {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 5px 10px;
    cursor: pointer;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

.container {
    padding: 28px 40px;
    width: 100%;
}

/* ============================================================
   Stat cards
   ============================================================ */

.stat-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    padding: 16px 20px;
    border-radius: 4px;
}

.stat-label {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
}

.stat-value {
    font-family: var(--mono);
    font-size: 28px;
    font-weight: 600;
    line-height: 1;
}
.stat-value.green { color: var(--green); }
.stat-value.red   { color: var(--red); }
.stat-value.amber { color: var(--amber); }
.stat-value.muted { color: var(--muted); }

/* ============================================================
   Badges & status dots
   ============================================================ */

.badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 2px;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.05em;
    font-family: var(--mono);
}
.badge.rest { background: #2d1a3d; color: #c084fc; }
.badge.url  { background: #1a1a2d; color: var(--muted); }

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    flex-shrink: 0;
}
.status-dot.up      { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.down    { background: var(--red);   box-shadow: 0 0 6px var(--red); animation: pulse 2s ease-in-out infinite; }
.status-dot.maint   { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.status-dot.unknown { background: var(--muted); }
/* admin variant */
.status-dot.on  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.status-dot.off { background: var(--muted); }

/* ============================================================
   Dashboard — main view
   ============================================================ */

.summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 220px));
    gap: 12px;
    margin-bottom: 28px;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
    align-items: start;
}

.section-label {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* Sites table */
.sites-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 12px;
}

.sites-table th {
    text-align: left;
    padding: 8px 12px;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    font-weight: 400;
    white-space: nowrap;
}

.sites-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.sites-table tr:last-child td { border-bottom: none; }
.sites-table tr:hover td { background: var(--bg3); }

.site-name { color: var(--text); font-weight: 500; }
.site-name a { color: var(--text); text-decoration: none; }
.site-name a:hover { color: var(--green); }
.site-url { color: var(--muted); font-size: 11px; display: block; margin-top: 2px; }

.updates-cell { color: var(--amber); }
.no-updates   { color: var(--muted); }
.update-detail { font-size: 10px; color: var(--amber); margin-top: 2px; }

.response-time       { color: var(--muted); }
.response-time.fast  { color: var(--green); }
.response-time.slow  { color: var(--amber); }

.uptime-val       { display: inline-block; min-width: 42px; text-align: right; }
.uptime-val.good  { color: var(--green); }
.uptime-val.ok    { color: var(--amber); }
.uptime-val.bad   { color: var(--red); }

.ssl-val.safe { color: var(--muted); }
.ssl-val.warn { color: var(--amber); }
.ssl-val.crit { color: var(--red); }

.unchecked { color: var(--muted); font-style: italic; }

/* Alerts panel */
.alerts-panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 16px;
}

.alert-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.alert-item:last-child { border-bottom: none; }

.alert-site {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
}
.alert-time {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
    float: right;
}
.alert-type {
    display: inline-block;
    font-family: var(--mono);
    font-size: 10px;
    margin-top: 3px;
    padding: 1px 5px;
    border-radius: 2px;
}
.alert-type.down    { background: var(--red-dim);   color: var(--red); }
.alert-type.up      { background: var(--green-dim); color: var(--green); }
.alert-type.updates { background: var(--amber-dim); color: var(--amber); }

/* ============================================================
   Dashboard — site detail page
   ============================================================ */

.back-link {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    text-decoration: none;
    letter-spacing: 0.06em;
}
.back-link:hover { color: var(--text); }

.site-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 20px 0 28px;
}
.site-title { font-family: var(--mono); font-size: 22px; font-weight: 600; color: var(--text); }
.site-detail-url { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}
.stats-grid .stat-value { font-size: 22px; }

.panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
}
.panel-title {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* Uptime blocks */
.uptime-blocks {
    display: grid;
    grid-template-columns: repeat(90, 1fr);
    gap: 3px;
    align-items: end;
}
.uptime-block {
    height: 32px;
    border-radius: 2px;
    cursor: pointer;
    position: relative;
}
.uptime-block.up      { background: var(--green); opacity: 0.8; }
.uptime-block.partial { background: var(--amber); }
.uptime-block.down    { background: var(--red); }
.uptime-block.no-data { background: var(--bg3); border: 1px solid var(--border); }
.uptime-block:hover   { opacity: 1; z-index: 10; }

.uptime-block .tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--mono);
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 3px;
    white-space: nowrap;
    z-index: 20;
}
.uptime-block:hover .tooltip { display: block; }

.uptime-labels {
    display: flex;
    justify-content: space-between;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
    margin-top: 6px;
}

.chart-wrap { position: relative; height: 160px; }

/* Recent checks log */
.checks-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11px; }
.checks-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
.checks-table tr:last-child td { border-bottom: none; }
.checks-table tr:hover td { background: var(--bg3); }

/* ============================================================
   Colour utilities
   ============================================================ */
.good  { color: var(--green); }
.ok    { color: var(--amber); }
.bad   { color: var(--red); }
.green { color: var(--green); }
.amber { color: var(--amber); }
.red   { color: var(--red); }
.muted { color: var(--muted); }

/* ============================================================
   Admin — auth pages
   ============================================================ */

.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 60px);
}

.auth-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 36px 40px;
    width: 100%;
    max-width: 400px;
}

.auth-title {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.auth-sub {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 24px;
    line-height: 1.6;
}

.secret-box {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 10px;
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.1em;
    text-align: center;
    margin-bottom: 16px;
    color: var(--green);
    word-break: break-all;
}

#qrcode { display: flex; justify-content: center; margin-bottom: 16px; }
#qrcode canvas, #qrcode img { border-radius: 4px; }

/* ============================================================
   Admin — forms
   ============================================================ */

.form-group { margin-bottom: 18px; }

label {
    display: block;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

label .hint {
    text-transform: none;
    letter-spacing: 0;
    font-size: 10px;
    color: var(--muted);
    font-weight: 400;
    margin-left: 6px;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
select,
textarea {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--green); }
select option { background: var(--bg3); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ============================================================
   Admin — buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 3px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    letter-spacing: 0.03em;
}
.btn:hover { text-decoration: none; }

.btn-primary   { background: var(--green-dim); border-color: var(--green);  color: var(--green); }
.btn-primary:hover  { background: #1f4d2e; }

.btn-secondary { background: var(--bg3);       border-color: var(--border); color: var(--muted); }
.btn-secondary:hover { color: var(--text); border-color: #3a3e3b; }

.btn-danger    { background: var(--red-dim);   border-color: var(--red);    color: var(--red); }
.btn-danger:hover   { background: #4d1f1f; }

.btn-amber     { background: var(--amber-dim); border-color: var(--amber);  color: var(--amber); }
.btn-amber:hover    { background: #4d3a0d; }

.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-actions { display: flex; gap: 8px; margin-top: 24px; flex-wrap: wrap; }

/* ============================================================
   Admin — alert banners
   ============================================================ */

.alert {
    padding: 10px 14px;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 12px;
    margin-bottom: 20px;
    border: 1px solid;
}
.alert-success { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.alert-error   { background: var(--red-dim);   border-color: var(--red);   color: var(--red); }

/* ============================================================
   Admin — page structure
   ============================================================ */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-title {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text);
}

/* Sites data table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 12px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.data-table th {
    text-align: left;
    padding: 10px 14px;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    font-weight: 400;
    background: var(--bg3);
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }

.td-actions { display: flex; gap: 6px; }

/* Tier comparison matrix (site edit form) */
.tier-matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 10px;
    color: var(--muted);
}
.tier-matrix th, .tier-matrix td {
    padding: 5px 10px;
    border: 1px solid var(--border);
    text-align: center;
}
.tier-matrix th:first-child, .tier-matrix td:first-child {
    text-align: left;
    color: var(--text);
}
.tier-matrix thead th { background: var(--bg3); font-weight: 600; color: var(--text); }
.tier-matrix td { color: var(--muted); }

/* Settings sections */
.settings-section {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 24px;
    margin-bottom: 20px;
}

.section-title {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* Conditional site type fields */
.site-fields         { display: none; }
.site-fields.visible { display: block; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 12px;
}

/* Horizontal scroll wrapper for wide tables on small screens */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============================================================
   Dashboard — tab navigation
   ============================================================ */

.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.tab-btn {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.tab-btn:hover { color: var(--text); text-decoration: none; }
.tab-btn.active { color: var(--green); border-bottom-color: var(--green); }

/* ============================================================
   Dashboard — server health bars
   ============================================================ */

.server-bar-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.server-bar {
    width: 52px;
    height: 4px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

.server-bar-fill {
    height: 100%;
    border-radius: 2px;
}
.server-bar-fill.good { background: var(--green); }
.server-bar-fill.ok   { background: var(--amber); }
.server-bar-fill.bad  { background: var(--red); }

/* ============================================================
   Responsive — Tablet (≤960px)
   ============================================================ */
@media (max-width: 960px) {
    header   { padding: 14px 24px; }
    .container { padding: 20px 24px; }

    /* Stack alerts below sites table */
    .grid { grid-template-columns: 1fr; }

    /* Summary: 2×2 */
    .summary { grid-template-columns: repeat(2, 1fr); }

    /* Detail stats: 3 per row */
    .stats-grid { grid-template-columns: repeat(3, 1fr); }

    /* Admin: collapse 2-col form rows */
    .form-row { grid-template-columns: 1fr; }

    /* Hide less critical columns on the sites table */
    .col-type,
    .col-7d,
    .col-30d { display: none; }
}

/* ============================================================
   Responsive — Mobile (≤600px)
   ============================================================ */
@media (max-width: 600px) {
    header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .header-time { display: none; }

    .container { padding: 14px 16px; }

    /* Summary: 2×2 */
    .summary { grid-template-columns: repeat(2, 1fr); }

    /* Detail stats: 2 per row */
    .stats-grid { grid-template-columns: repeat(2, 1fr); }

    /* Uptime blocks: switch to 30-column grid (3 rows × 30 days) on mobile */
    .uptime-blocks {
        display: grid;
        grid-template-columns: repeat(30, 1fr);
        gap: 2px;
    }

    /* Hide more table columns, keep: site, status, updates, last check */
    .col-type,
    .col-response,
    .col-24h,
    .col-7d,
    .col-30d,
    .col-ssl { display: none; }

    /* Smaller font in table */
    .sites-table { font-size: 11px; }
    .sites-table td, .sites-table th { padding: 8px 8px; }

    /* Uptime blocks: fixed height in grid layout */
    .uptime-block { height: 18px; }

    /* Panel padding */
    .panel { padding: 14px; }

    /* Admin */
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .btn-actions { flex-direction: column; }
    .settings-section { padding: 16px; }
    .data-table td, .data-table th { padding: 8px 10px; }
    .td-actions { flex-wrap: wrap; }

    /* Auth box full width */
    .auth-box { padding: 24px 20px; }
}
