:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #242836;
    --border: #2e3345;
    --text: #e8eaef;
    --text-muted: #8b92a8;
    --primary: #4f7cff;
    --primary-hover: #3d6aef;
    --error: #ff5c6c;
    --success: #3dd68c;
    --radius: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.875rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-right: auto;
    margin-left: 1.5rem;
}

.header-nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.header-nav-link:hover {
    color: var(--text);
}

.logo {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-badge {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.main {
    flex: 1;
    padding: 2rem 1.5rem;
}

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

.container-narrow {
    max-width: 560px;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Auth */
.auth-card {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.auth-step {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.back-link {
    display: block;
    margin-top: 1.25rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-decoration: none;
}

.back-link:hover {
    color: var(--text);
}

/* Form */
.form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.field label,
.instance-field label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
}

.field input,
.instance-field input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color 0.15s;
}

.field input:focus,
.instance-field input:focus {
    border-color: var(--primary);
}

.card-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.channels-fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin: 0;
}

.channels-fieldset legend {
    padding: 0 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.channel-row {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.channel-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
}

.instance-field {
    margin-top: 0.625rem;
    padding-left: 1.625rem;
}

.instance-field.hidden {
    display: none;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: 6px;
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-error {
    background: rgba(255, 92, 108, 0.12);
    border: 1px solid rgba(255, 92, 108, 0.3);
    color: var(--error);
}

.alert ul {
    margin-left: 1.25rem;
}

/* CRM grid */
.crm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.crm-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s, transform 0.15s;
}

.crm-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.crm-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
}

.crm-alfa .crm-icon { background: rgba(79, 124, 255, 0.2); color: #4f7cff; }
.crm-tallanto .crm-icon { background: rgba(61, 214, 140, 0.2); color: #3dd68c; }
.crm-vetmanager .crm-icon { background: rgba(255, 180, 60, 0.2); color: #ffb43c; }

.crm-name {
    font-weight: 600;
    font-size: 1.05rem;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.breadcrumb {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
}

.breadcrumb a:hover {
    color: var(--primary);
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background: var(--surface);
}

.cell-name {
    font-weight: 500;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Tags */
.channel-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.tag {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.tag-whatsapp { background: rgba(37, 211, 102, 0.15); color: #25d366; }
.tag-telegram { background: rgba(42, 171, 238, 0.15); color: #2aabe8; }
.tag-max { background: rgba(255, 92, 108, 0.15); color: #ff5c6c; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 1rem;
}

.container-profile-wide {
    max-width: 960px;
}

.container-profile {
    max-width: 960px;
}

.profile-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.profile-card h1 {
    text-align: center;
}

.profile-card .subtitle {
    text-align: center;
    margin-bottom: 1.25rem;
}

.toggles-card h2 {
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
}

.form-actions-center {
    justify-content: center;
}

.client-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
}

.client-link:hover {
    color: var(--primary);
}

.col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.inline-form {
    display: inline;
}

.btn-danger {
    background: transparent;
    color: var(--error);
    border: 1px solid rgba(255, 92, 108, 0.35);
}

.btn-danger:hover {
    background: rgba(255, 92, 108, 0.12);
    border-color: var(--error);
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.875rem 0;
    border-top: 1px solid var(--border);
}

.toggle-row:first-of-type {
    border-top: none;
    padding-top: 0;
}

.toggle-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.toggle-title {
    font-weight: 500;
}

.toggle-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 24px;
    transition: background 0.2s;
}

.slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.switch input:checked + .slider {
    background: rgba(79, 124, 255, 0.25);
    border-color: var(--primary);
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
    background: var(--primary);
}

.alert-success {
    background: rgba(61, 214, 140, 0.12);
    border: 1px solid rgba(61, 214, 140, 0.35);
    color: var(--success);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.field-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

.api-fieldset {
    margin-top: 0.5rem;
}

.bots-section {
    margin-top: 0.25rem;
}

.bots-section-header h2 {
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
}

.bots-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
}

.bot-tab {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8125rem;
    white-space: nowrap;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.bot-tab:hover {
    color: var(--text);
    border-color: var(--primary);
}

.bot-tab.active {
    color: var(--text);
    border-color: var(--primary);
    background: rgba(79, 124, 255, 0.15);
}

.bot-tab-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--success);
    background: rgba(61, 214, 140, 0.15);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

.bot-panel {
    display: none;
}

.bot-panel.active {
    display: block;
}

.bot-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.bot-form-header h3 {
    font-size: 1rem;
    margin: 0;
}

.inline-toggle {
    margin: 0;
}

.bot-desc {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
}

.bot-form textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9375rem;
    font-family: inherit;
    resize: vertical;
    min-height: 4rem;
}

.bot-form textarea:focus,
.bot-form select:focus {
    outline: none;
    border-color: var(--primary);
}

.bot-form select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9375rem;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .field-row {
        grid-template-columns: 1fr;
    }
}

.button-row {
    border-top: 1px solid var(--border);
    padding-top: 0.875rem;
    margin-top: 0.875rem;
}

.button-row:first-child {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}

.button-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.button-row-delete:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

.container-logs-wide {
    max-width: 100%;
    padding: 0 0.5rem;
}

.logs-section-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.logs-section-tab {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.logs-section-tab:hover {
    color: var(--text);
    border-color: var(--primary);
}

.logs-section-tab.active {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--primary);
}

.logs-bot-tabs {
    margin-bottom: 1.25rem;
}

.table-wrap-logs {
    overflow-x: auto;
}

.table-logs {
    font-size: 0.8125rem;
    white-space: nowrap;
}

.table-logs .cell-truncate {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-logs .cell-command {
    font-weight: 600;
    font-family: ui-monospace, monospace;
}

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.status-sent {
    background: rgba(61, 214, 140, 0.15);
    color: var(--success);
}

.status-failed {
    background: rgba(255, 92, 108, 0.15);
    color: var(--error);
}

.status-skipped {
    background: rgba(139, 146, 168, 0.15);
    color: var(--text-muted);
}

.status-confirmed {
    background: rgba(61, 214, 140, 0.15);
    color: var(--success);
}

.status-cancelled {
    background: rgba(255, 92, 108, 0.15);
    color: var(--error);
}

.status-pending_confirm,
.status-pending_cancel {
    background: rgba(255, 193, 7, 0.15);
    color: #c9a227;
}

.table-logs .cell-mono {
    font-family: ui-monospace, monospace;
    font-size: 0.8rem;
    word-break: break-all;
}

.table-logs .col-raw-webhook {
    white-space: nowrap;
}

.raw-webhook-dialog {
    width: min(90vw, 52rem);
    max-height: 85vh;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.raw-webhook-dialog::backdrop {
    background: rgba(0, 0, 0, 0.55);
}

.raw-webhook-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.raw-webhook-pre {
    margin: 0;
    padding: 1rem;
    max-height: calc(85vh - 3.5rem);
    overflow: auto;
    font-family: ui-monospace, monospace;
    font-size: 0.8rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.pagination-info {
    color: var(--text-muted);
    font-size: 0.875rem;
}
