:root {
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-surface-alt: #f8fafc;
    --color-border: #e2e8f0;
    --color-border-strong: #cbd5e1;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-text-soft: #94a3b8;
    --color-primary: #0d6fb8;
    --color-primary-dark: #0a5790;
    --color-primary-soft: #e6f1fa;
    --color-success: #0f9d58;
    --color-success-soft: #e6f7ef;
    --color-warning: #d97706;
    --color-warning-soft: #fef3e2;
    --color-danger: #dc2626;
    --color-danger-soft: #fee2e2;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; }

/* Login */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #e6f1fa 0%, #f5f7fa 50%, #e6f7ef 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
    animation: fadeUp 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-logo {
    width: 48px; height: 48px;
    border-radius: 12px;
    background: var(--color-primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
    margin-bottom: 20px;
}

.login-card h1 { font-size: 22px; font-weight: 600; margin-bottom: 4px; }
.login-card p.sub { color: var(--color-text-muted); margin-bottom: 28px; line-height: 1.5; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }

.input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: white;
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(13, 111, 184, 0.12);
}

.input-sm { padding: 6px 8px; font-size: 13px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

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

.btn-secondary { background: white; color: var(--color-text); border: 1px solid var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-alt); border-color: var(--color-text-muted); }

.btn-ghost { color: var(--color-text-muted); padding: 6px 10px; }
.btn-ghost:hover { color: var(--color-text); background: var(--color-surface-alt); }

.btn-remove {
    width: 28px; height: 28px;
    border-radius: 50%;
    color: var(--color-text-muted);
    font-size: 18px;
    line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}
.btn-remove:hover { background: var(--color-danger-soft); color: var(--color-danger); }

.error-msg {
    padding: 10px 12px;
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

/* Dashboard */
.dashboard { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 14px 32px;
    display: flex; align-items: center; justify-content: space-between;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.topbar-logo {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--color-primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}

.topbar h1 { font-size: 15px; font-weight: 600; }
.topbar-sub { color: var(--color-text-muted); font-size: 12px; }

.container {
    max-width: 1120px;
    width: 100%;
    margin: 0 auto;
    padding: 32px;
}

.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.page-header p { color: var(--color-text-muted); line-height: 1.5; max-width: 680px; }

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--color-border);
}

.tab {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--color-text); }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}

.card-title { font-size: 16px; font-weight: 600; }
.card-subtitle { color: var(--color-text-muted); font-size: 13px; margin-top: 4px; max-width: 560px; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
.badge-primary { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-muted { background: var(--color-surface-alt); color: var(--color-text-muted); }

/* Rule chips (HOJE view) */
.rule-list { display: flex; flex-direction: column; gap: 10px; }

.rule-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition);
}
.rule-chip:hover { border-color: var(--color-border-strong); }
.rule-chip.done { opacity: 0.7; }

.rule-chip-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.rule-time {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 15px;
    font-weight: 600;
    color: var(--color-primary-dark);
    background: var(--color-primary-soft);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
}

.rule-arrow { color: var(--color-text-soft); font-size: 14px; }
.rule-target { font-weight: 500; }
.rule-days-ahead {
    font-size: 12px;
    color: var(--color-text-muted);
    background: white;
    border: 1px solid var(--color-border);
    padding: 2px 8px;
    border-radius: 999px;
}

/* Preview block (appointments table) */
.preview-block {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 14px;
    background: var(--color-surface-alt);
}
.preview-block:last-child { margin-bottom: 0; }

.preview-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.preview-block-header .muted { color: var(--color-text-muted); font-weight: 400; }

.appt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: white;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.appt-table th, .appt-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.appt-table th {
    font-weight: 600;
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--color-surface-alt);
}

.appt-table tr:last-child td { border-bottom: none; }
.appt-table tr:hover td { background: var(--color-surface-alt); }

.mono { font-family: 'SF Mono', Monaco, monospace; font-size: 13px; }

/* Weekly grid */
.weekly-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
}

.day-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px;
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 180px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.day-card:hover { border-color: var(--color-border-strong); }
.day-card.highlighted {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(13, 111, 184, 0.1);
}

.day-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.day-card-name { font-weight: 600; }

.hoje-pill {
    font-size: 10px;
    background: var(--color-primary);
    color: white;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.rule-rows { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.rule-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 6px 8px;
    background: var(--color-surface-alt);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.rule-row-main {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 12px;
}

.rule-row .rule-time { font-size: 12px; padding: 1px 6px; }

.empty-state-sm {
    padding: 12px;
    text-align: center;
    color: var(--color-text-soft);
    font-size: 12px;
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-sm);
}

.rule-add-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px dashed var(--color-border);
}

.rule-add-form .input { min-width: 0; width: 100%; }
.rule-add-form button { grid-column: span 2; }

.mini-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mini-field label {
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.rule-add-form.inline {
    margin-top: 10px;
    border-top: 1px dashed var(--color-border);
}

/* Overrides */
.override-new-form {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
    padding: 16px;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.form-field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.override-list { display: flex; flex-direction: column; gap: 12px; }

.override-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    background: var(--color-surface);
    transition: border-color var(--transition);
}
.override-card:hover { border-color: var(--color-border-strong); }

.override-card-header { margin-bottom: 12px; }
.override-date { font-weight: 600; font-size: 15px; }
.override-sub { color: var(--color-text-muted); font-size: 12px; margin-top: 2px; }

@media (max-width: 720px) {
    .override-new-form { grid-template-columns: 1fr; }
    .container { padding: 20px 16px; }
    .topbar { padding: 12px 16px; }
    .rule-add-form { grid-template-columns: 1fr; }
    .rule-add-form button { grid-column: span 1; }
}

.empty-state {
    padding: 32px 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
    background: var(--color-surface-alt);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--color-border-strong);
}

/* Toast */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--color-text);
    color: white;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 200ms cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 340px;
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }

@keyframes slideIn {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.loader {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

.loader-dark {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
    margin-right: 8px;
}

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

/* Message templates */
.template-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 14px;
    background: var(--color-surface);
}
.template-card:last-child { margin-bottom: 0; }

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.template-title { font-weight: 600; font-size: 15px; }
.template-sub { color: var(--color-text-muted); font-size: 12px; margin-top: 2px; max-width: 480px; }

.template-body {
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--color-text);
    max-height: 360px;
    overflow: auto;
}

/* Automations */
.automation-group { margin-bottom: 20px; }
.automation-group:last-child { margin-bottom: 0; }

.automation-group-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 10px;
}

.automation-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: var(--color-surface-alt);
}

.automation-title { font-weight: 500; }
.automation-sub { color: var(--color-text-muted); font-size: 12px; margin-top: 2px; }
.automation-sub code {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 11px;
    background: white;
    border: 1px solid var(--color-border);
    padding: 1px 6px;
    border-radius: 3px;
}

.automation-note {
    color: var(--color-text-muted);
    font-size: 12px;
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--color-primary-soft);
    border-radius: var(--radius-sm);
}
.automation-note code {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 11px;
    background: white;
    padding: 1px 6px;
    border-radius: 3px;
}

.full-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
    color: var(--color-text-muted);
    font-size: 13px;
}
