/*
CaddyPanel — Main Stylesheet

Design system: neutral gray base + colored accents per theme.
Only accent colors (buttons, active tabs, links, highlights) vary by theme.
Backgrounds and text stay neutral for all themes.
*/

/* ===== CSS Variables per theme ===== */
:root, .theme-light-gray   { --accent: #4b5563; --accent-hover: #374151; --accent-contrast: #fff; }
.theme-light-blue          { --accent: #3b82f6; --accent-hover: #2563eb; --accent-contrast: #fff; }
.theme-light-green         { --accent: #22c55e; --accent-hover: #16a34a; --accent-contrast: #fff; }
.theme-light-violet        { --accent: #8b5cf6; --accent-hover: #7c3aed; --accent-contrast: #fff; }
.theme-light-orange        { --accent: #f97316; --accent-hover: #ea580c; --accent-contrast: #fff; }

.theme-dark-gray           { --accent: #9ca3af; --accent-hover: #d1d5db; --accent-contrast: #111; }
.theme-dark-blue           { --accent: #60a5fa; --accent-hover: #93c5fd; --accent-contrast: #111; }
.theme-dark-green          { --accent: #4ade80; --accent-hover: #86efac; --accent-contrast: #111; }
.theme-dark-violet         { --accent: #a78bfa; --accent-hover: #c4b5fd; --accent-contrast: #111; }
.theme-dark-orange         { --accent: #fb923c; --accent-hover: #fdba74; --accent-contrast: #111; }

/* ===== Light theme base ===== */
:root, [class*="theme-light-"] {
    --bg-page: #f3f4f6;
    --bg-card: #ffffff;
    --bg-elevated: #f9fafb;
    --bg-input: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-heading: #1f2937;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* ===== Dark theme base ===== */
[class*="theme-dark-"] {
    --bg-page: #111827;
    --bg-card: #1f2937;
    --bg-elevated: #374151;
    --bg-input: #374151;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-heading: #e5e7eb;
    --border: #374151;
    --border-strong: #4b5563;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
}

/* ===== Base styles ===== */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    margin: 20px;
    background-color: var(--bg-page);
    color: var(--text-primary);
}

h1, h2 { color: var(--text-heading); margin-bottom: 15px; }
h3 { margin-top: 1.2em; margin-bottom: 0.8em; }
h4 { margin-top: 1em; margin-bottom: 0.6em; font-size: 1.1em; }

h1 {
    text-align: center;
    border-bottom: 2px solid var(--border);
    padding-bottom: 10px;
}

/* ===== Forms ===== */
form {
    background-color: var(--bg-card);
    padding: 20px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
#configurator-tab > form#caddy-config-form {
    background-color: transparent;
    padding: 0;
    box-shadow: none;
    margin-bottom: 0;
}

.form-group { margin-bottom: 10px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--text-primary);
}
.form-group-inline label {
    display: inline-block;
    margin-left: 5px;
    margin-bottom: 0;
    font-weight: normal;
}
.form-group-inline input[type="checkbox"] { vertical-align: middle; }

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: calc(100% - 22px);
    padding: 10px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    font-size: 1em;
    background-color: var(--bg-input);
    color: var(--text-primary);
}

/* ===== Buttons ===== */
button, .action-btn {
    background-color: var(--accent);
    color: var(--accent-contrast);
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    transition: background-color 0.2s;
    text-decoration: none;
    display: inline-block;
    vertical-align: middle;
    margin: 2px;
}
button:hover, .action-btn:hover { background-color: var(--accent-hover); }

.add-remove-btn { padding: 5px 10px; font-size: 0.9em; }
#add-host-btn { background-color: #22c55e; color: #fff; }
#add-host-btn:hover { background-color: #16a34a; }

.edit-btn { background-color: #f59e0b; color: #fff; }
.edit-btn:hover { background-color: #d97706; }
.delete-btn { background-color: #ef4444; color: #fff; }
.delete-btn:hover { background-color: #dc2626; }
.stats-btn { background-color: #06b6d4; color: #fff; }
.stats-btn:hover { background-color: #0891b2; }

/* ===== Tabs ===== */
.tab-container {
    width: 100%;
    border: 1px solid var(--border);
    background-color: var(--bg-elevated);
    border-radius: 8px;
    overflow: hidden;
}
.tab-buttons {
    overflow: hidden;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-elevated);
}
.tab-buttons button {
    background-color: inherit;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.2s;
    font-size: 1em;
    color: var(--text-secondary);
    border-radius: 0;
    border-right: 1px solid var(--border);
}
.tab-buttons button:last-child { border-right: none; }
.tab-buttons button:hover { background-color: var(--bg-card); color: var(--text-primary); }
.tab-buttons button.active {
    background-color: var(--bg-card);
    font-weight: bold;
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}
.tab-content {
    padding: 20px;
    border-top: none;
    background-color: var(--bg-card);
    display: none;
}
#preferences-tab small { display: block; margin-top: 5px; color: var(--text-secondary); font-size: 0.9em; }

/* ===== Table ===== */
#sites-table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 0.95em; }
#sites-table th, #sites-table td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: middle; }
#sites-table th { background-color: var(--bg-elevated); color: var(--text-secondary); font-weight: 600; font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.03em; }
#sites-table td.actions { text-align: right; white-space: nowrap; }
#sites-table .action-btn { padding: 3px 6px; font-size: 0.85em; margin: 1px; }
#sites-table td input[type="checkbox"] { vertical-align: middle; margin: 0; }
#sites-table td a { color: var(--text-secondary); text-decoration: none; }
#sites-table td a:hover { text-decoration: underline; color: var(--accent); }
#sites-table th:nth-child(4), #sites-table th:nth-child(5) { text-align: center; }

/* ===== Raw Caddyfile ===== */
#raw-caddyfile-tab textarea {
    width: 98%;
    min-height: 400px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    white-space: pre;
    border: 1px solid var(--border-strong);
    background-color: var(--bg-input);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 4px;
}
#raw-caddyfile-tab button { margin-top: 10px; }

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}
.modal-content {
    background-color: var(--bg-card);
    margin: 5% auto;
    padding: 25px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    width: 80%;
    max-width: 700px;
    position: relative;
    color: var(--text-primary);
}
.close-modal-btn {
    color: var(--text-secondary);
    position: absolute;
    top: 10px; right: 20px;
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
}
.close-modal-btn:hover, .close-modal-btn:focus { color: var(--text-primary); text-decoration: none; cursor: pointer; }
.modal-content h2 { margin-top: 0; }
.modal-content h3 {
    font-size: 1.2em;
    margin-top: 1.5em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 5px;
}
.modal-content h4 { font-size: 1em; margin-top: 1em; margin-bottom: 0.5em; }
.modal-content .options-section {
    padding: 10px;
    margin-top: 5px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--bg-elevated);
}
.modal-content .modal-toggle-link { text-decoration: none; color: inherit; font-weight: bold; cursor: pointer; }
.modal-content .modal-toggle-link:hover { text-decoration: underline; }
.modal-actions { margin-top: 20px; text-align: right; }
.modal-actions button { margin-left: 10px; }
#modal-cancel-btn { background-color: var(--text-secondary); color: #fff; }
#modal-cancel-btn:hover { background-color: var(--text-primary); }

.modal-toggle-buttons {
    margin-top: 15px;
    margin-bottom: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
    display: flex;
    flex-wrap: wrap;
}
.modal-toggle-btn {
    margin-right: 5px; margin-bottom: 5px;
    font-size: 0.85em; padding: 3px 8px;
    background-color: var(--text-secondary);
    color: #fff;
    border: none;
}
.modal-toggle-btn:hover { opacity: 0.85; }

/* ===== Auth pages (login/setup) ===== */
.auth-page {
    background-color: var(--bg-page);
    color: var(--text-primary);
}
.auth-page .auth-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border-strong);
}
.auth-page h1 { color: var(--accent); border-bottom-color: var(--border); }
.auth-page h2 { color: var(--text-heading); }
.auth-page input {
    border-color: var(--border-strong);
    background-color: var(--bg-input);
    color: var(--text-primary);
}
.auth-page button {
    background-color: var(--accent);
    color: var(--accent-contrast);
}

/* ===== Toast ===== */
#toast-container {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.toast {
    background-color: #333;
    color: white;
    padding: 12px 20px;
    margin-bottom: 10px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.5s ease, transform 0.5s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 250px;
    max-width: 400px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.success { background-color: #22c55e; }
.toast.danger, .toast.error { background-color: #ef4444; }
.toast.warning { background-color: #f59e0b; color: #333; }
.toast.info { background-color: #06b6d4; }
.toast .toast-message { flex-grow: 1; }
.toast .toast-close-btn {
    background: none; border: none; color: white;
    font-size: 1.2em; margin-left: 15px;
    cursor: pointer; padding: 0 5px; line-height: 1;
}
.toast.warning .toast-close-btn { color: #333; }

/* ===== Flash messages (legacy) ===== */
.flash-message {
    padding: 10px; margin: 10px 0; border-radius: 4px;
    border: 1px solid transparent; font-weight: bold;
}
.flash-message.success { background-color: #d4edda; color: #155724; border-color: #c3e6cb; }
.flash-message.danger { background-color: #f8d7da; color: #721c24; border-color: #f5c6cb; }
.flash-message.warning { background-color: #fff3cd; color: #856404; border-color: #ffeeba; }
.flash-message.info { background-color: #d1ecf1; color: #0c5460; border-color: #bee5eb; }