/* ═══════════════════════════════════════════
   Automation Rules — Chatwoot Dark Theme
   ═══════════════════════════════════════════ */

:root {
    --bg-sidebar: #1b1f23;
    --bg-main: #151718;
    --bg-card: #25292e;
    --bg-input: #1b1f23;
    --bg-hover: #2d3239;
    --bg-modal: #25292e;
    --border: #3a3f47;
    --border-light: #2d3239;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #6b7280;
    --accent: #1f93ff;
    --accent-hover: #1a7fd9;
    --accent-glow: rgba(31, 147, 255, 0.15);
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #27ae60;
    --toggle-off: #4a4f57;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.5);
    --transition: 200ms ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ── */

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-light);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: white;
}

.brand-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.sidebar-nav {
    padding: 12px 8px;
    flex: 1;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 12px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-item.active svg {
    opacity: 1;
}

/* ── Main Content ── */

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.page-header-left h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 600px;
    line-height: 1.6;
}

/* ── Buttons ── */

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(31, 147, 255, 0.3);
}

.btn-cancel {
    padding: 10px 20px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-cancel:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    padding: 10px 20px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-add-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    color: var(--accent);
    border: none;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 8px;
}

.btn-add-row:hover {
    color: var(--accent-hover);
}

/* ── Rules Table ── */

.rules-table-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.rules-table {
    width: 100%;
    border-collapse: collapse;
}

.rules-table thead th {
    padding: 14px 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-sidebar);
}

.rules-table tbody tr {
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition);
}

.rules-table tbody tr:last-child {
    border-bottom: none;
}

.rules-table tbody tr:hover {
    background: var(--bg-hover);
}

.rules-table td {
    padding: 16px 20px;
    font-size: 14px;
}

.rule-name {
    font-weight: 600;
    color: var(--text-primary);
}

.rule-description {
    color: var(--text-secondary);
    font-size: 13px;
}

.rule-date {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
}

.rule-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    background: transparent;
}

.btn-icon-edit {
    color: var(--accent);
}

.btn-icon-edit:hover {
    background: var(--accent-glow);
}

.btn-icon-delete {
    color: var(--danger);
}

.btn-icon-delete:hover {
    background: rgba(231, 76, 60, 0.15);
}

/* ── Toggle Switch ── */

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--toggle-off);
    border-radius: 24px;
    transition: all var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: all var(--transition);
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ── Empty State ── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.empty-state svg {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
    color: var(--text-muted);
}

/* ── Loading State ── */

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-state p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ── Modal ── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 250ms ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-modal);
    border-radius: 12px;
    border: 1px solid var(--border);
    width: 680px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-modal);
    transform: scale(0.95) translateY(10px);
    transition: all 250ms ease;
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-small {
    width: 440px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px 0;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px 28px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 28px 24px;
    border-top: 1px solid var(--border-light);
}

/* ── Form ── */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239aa0a6' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-group select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ── Form Sections (Conditions / Actions) ── */

.form-section {
    margin-bottom: 20px;
}

.form-section-header {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

/* ── Condition Row ── */

.condition-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    animation: fadeIn 200ms ease;
}

.condition-row select,
.condition-row input {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

.condition-row select:focus,
.condition-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.condition-row select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239aa0a6' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.condition-row select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

.condition-attribute { flex: 0 0 180px; }
.condition-operator { flex: 0 0 160px; }
.condition-value { flex: 1; }

.btn-remove-row {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
    align-self: center;
}

.btn-remove-row:hover {
    background: rgba(231, 76, 60, 0.15);
    border-color: var(--danger);
    color: var(--danger);
}

/* ── Action Row ── */

.action-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    animation: fadeIn 200ms ease;
}

.action-row select,
.action-row input {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

.action-row select:focus,
.action-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.action-row select {
    cursor: pointer;
    flex: 0 0 200px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239aa0a6' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.action-row select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

.action-value { flex: 1; }
.action-value-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.action-value-group input {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

.action-value-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.action-type-select-group {
    display: flex;
    gap: 6px;
    flex: 0 0 200px;
}
.action-type-select-group select {
    flex: 1;
}
.attachment-type-select {
    flex: 0 0 100px !important;
}

/* ── Animations ── */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Toast Notification ── */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 300ms ease, fadeOut 300ms ease 2.7s forwards;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; visibility: hidden; }
}

/* ── Scrollbar ── */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Responsive ── */

@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 20px; }
    .page-header { flex-direction: column; gap: 16px; }
    .modal { width: 95vw; }
    .condition-row, .action-row { flex-wrap: wrap; }
    .condition-attribute, .condition-operator { flex: 1 1 45%; }
    .condition-value { flex: 1 1 100%; }
}
