/* ========================================
   H&L Cleaning Co. — Admin Portal Styles
   Matches the site's botanical aesthetic
   ======================================== */

/* ---- Variables (from site design system) ---- */
:root {
    --sage: #7a9a7e;
    --sage-dark: #5c7a5f;
    --sage-deeper: #4a6b4d;
    --sage-light: #a8c5ab;
    --sage-pale: #dce8dd;
    --sage-ghost: #eef3ee;
    --cream: #faf8f4;
    --cream-warm: #f5f0e8;
    --linen: #f0ece4;
    --tan: #d4c5a9;
    --warm-brown: #8a7660;
    --bark: #5e4d3b;
    --text: #3a3a36;
    --text-light: #6b6b64;
    --text-muted: #9a9a92;
    --white: #ffffff;
    --radius: 12px;
    --radius-lg: 20px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(90,80,60,0.06);
    --shadow: 0 4px 20px rgba(90,80,60,0.08);
    --shadow-lg: 0 8px 40px rgba(90,80,60,0.12);
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Jost', -apple-system, sans-serif;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --red: #c0392b;
    --red-light: #fdf0ef;
    --green: #27ae60;
    --green-light: #eefbf3;
    --amber: #f39c12;
    --amber-light: #fef9ec;
}

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

body {
    font-family: var(--font-body);
    color: var(--text);
    background: var(--cream);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ========== LOGIN PAGE ========== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--sage-ghost) 0%, var(--cream) 50%, var(--cream-warm) 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    box-shadow: var(--shadow-lg);
}

.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 36px;
}

.login-logo {
    width: 36px;
    height: 32px;
    color: var(--sage);
}

.login-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 500;
    color: var(--bark);
}

.login-error {
    background: var(--red-light);
    color: var(--red);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 20px;
    border-left: 3px solid var(--red);
}

/* ---- Forms ---- */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input,
.select-input,
.textarea-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--sage-pale);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: var(--text);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.select-input:focus,
.textarea-input:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(122, 154, 126, 0.15);
}

.textarea-input {
    resize: vertical;
    min-height: 80px;
}

.select-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6b64' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--sage);
    color: var(--white);
}
.btn-primary:hover:not(:disabled) {
    background: var(--sage-dark);
}

.btn-success {
    background: var(--green);
    color: var(--white);
}
.btn-success:hover:not(:disabled) {
    background: #219a52;
}

.btn-warning {
    background: var(--amber);
    color: var(--white);
}
.btn-warning:hover:not(:disabled) {
    background: #d68910;
}

.btn-outline {
    background: transparent;
    color: var(--text-light);
    border: 1.5px solid var(--sage-pale);
}
.btn-outline:hover:not(:disabled) {
    border-color: var(--sage);
    color: var(--sage-dark);
}

.login-form .btn {
    width: 100%;
    margin-top: 8px;
    padding: 14px;
}

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-style: italic;
}

/* ========== PORTAL HEADER ========== */

.portal-header {
    background: var(--white);
    border-bottom: 1px solid var(--sage-pale);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    width: 28px;
    height: 24px;
    color: var(--sage);
}

.header-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--bark);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-link {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-light);
    text-decoration: none;
    transition: all var(--transition);
}

.nav-link:hover {
    color: var(--sage-dark);
    background: var(--sage-ghost);
}

.nav-link.active {
    color: var(--sage-dark);
    background: var(--sage-ghost);
    font-weight: 500;
}

.nav-logout {
    color: var(--text-muted);
    margin-left: 12px;
}

/* ========== PORTAL MAIN ========== */

.portal-main {
    padding: 32px 24px 64px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.page-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 500;
    color: var(--bark);
    margin-bottom: 4px;
}

.page-subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

/* ---- Cards ---- */
.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.card-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--bark);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--sage-pale);
}

/* ========== DASHBOARD ========== */

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ---- File List ---- */
.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--sage-ghost);
}

.file-item:last-child {
    border-bottom: none;
}

.file-name {
    font-weight: 500;
    color: var(--text);
    font-size: 0.95rem;
}

.file-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.file-edit-link {
    font-size: 0.85rem;
    color: var(--sage);
    text-decoration: none;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--sage-pale);
    transition: all var(--transition);
}

.file-edit-link:hover {
    background: var(--sage-ghost);
    border-color: var(--sage-light);
}

/* ---- History List ---- */
.history-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--sage-ghost);
}

.history-item:last-child {
    border-bottom: none;
}

.history-action {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.history-action.applied {
    background: var(--green-light);
    color: var(--green);
}

.history-action.rolled_back {
    background: var(--amber-light);
    color: var(--amber);
}

.history-action.edit_generated {
    background: var(--sage-ghost);
    color: var(--sage-dark);
}

.history-action.discarded {
    background: var(--red-light);
    color: var(--red);
}

.history-file {
    font-weight: 500;
    font-size: 0.9rem;
    margin-left: 6px;
}

.history-instruction {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 4px;
    font-style: italic;
}

.history-time {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.history-empty {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-style: italic;
}

/* ========== EDITOR ========== */

.editor-controls {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.editor-controls .form-group {
    margin-bottom: 0;
}

.editor-controls .form-group:first-child {
    min-width: 180px;
}

@media (max-width: 768px) {
    .editor-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .editor-controls .btn {
        width: 100%;
    }
}

/* ---- Code Preview ---- */
.code-preview {
    background: var(--sage-ghost);
    border: 1px solid var(--sage-pale);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    tab-size: 2;
}

/* ---- Diff View ---- */
.diff-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .diff-container {
        grid-template-columns: 1fr;
    }
}

.diff-panel {
    min-width: 0;
}

.diff-label {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.diff-before {
    border-color: rgba(192,57,43,0.2);
    background: rgba(253,240,239,0.5);
}

.diff-after {
    border-color: rgba(39,174,96,0.2);
    background: rgba(238,251,243,0.5);
}

.diff-actions {
    display: flex;
    gap: 12px;
    padding-top: 8px;
}

/* ---- Applied State ---- */
.applied-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

/* ---- Alerts ---- */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    line-height: 1.5;
}

.alert-success {
    background: var(--green-light);
    color: var(--green);
    border-left: 3px solid var(--green);
}

.alert-error {
    background: var(--red-light);
    color: var(--red);
    border-left: 3px solid var(--red);
}

.alert-warning {
    background: var(--amber-light);
    color: #8a6d3b;
    border-left: 3px solid var(--amber);
}

.alert-info {
    background: var(--sage-ghost);
    color: var(--sage-deeper);
    border-left: 3px solid var(--sage);
    margin-bottom: 24px;
}

/* ---- Operation-level Diff ---- */
.diff-operation {
    margin-bottom: 16px;
    border: 1px solid var(--sage-pale);
    border-radius: var(--radius);
    overflow: hidden;
}

.diff-op-header {
    background: var(--sage-ghost);
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--sage-pale);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.diff-op-file {
    color: var(--sage-dark);
    font-family: monospace;
    font-size: 0.78rem;
    background: var(--white);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--sage-pale);
}

.diff-op-count {
    text-transform: uppercase;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.diff-op-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

.diff-op-panels .diff-panel {
    padding: 12px;
    min-width: 0;
}

.diff-op-panels .diff-panel:first-child {
    border-right: 1px solid var(--sage-pale);
}

.diff-op-panels .code-preview {
    max-height: 250px;
    margin: 0;
    font-size: 0.8rem;
}

.full-diff-toggle {
    margin: 16px 0;
}

.full-diff-toggle summary {
    cursor: pointer;
    color: var(--sage);
    font-size: 0.88rem;
    padding: 8px 0;
    user-select: none;
}

.full-diff-toggle summary:hover {
    color: var(--sage-dark);
}

@media (max-width: 768px) {
    .diff-op-panels {
        grid-template-columns: 1fr;
    }
    .diff-op-panels .diff-panel:first-child {
        border-right: none;
        border-bottom: 1px solid var(--sage-pale);
    }
}

/* ---- Backup Items ---- */
.backup-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--sage-ghost);
}

.backup-item:last-child {
    border-bottom: none;
}

.backup-info {
    font-size: 0.88rem;
}

.backup-date {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.backup-restore-btn {
    font-size: 0.82rem;
    padding: 4px 12px;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .login-card {
        padding: 36px 28px;
    }

    .header-inner {
        flex-direction: column;
        height: auto;
        padding: 12px 0;
        gap: 8px;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .card {
        padding: 20px;
    }

    .diff-actions,
    .applied-actions {
        flex-direction: column;
    }
}
