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

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #94a3b8;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --warn: #d97706;
    --header-h: 56px;
    --radius: 8px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); min-height: 100vh; }

/* Header */
.header { position: sticky; top: 0; z-index: 100; height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { max-width: 1600px; margin: 0 auto; padding: 0 24px; height: 100%; display: flex; align-items: center; gap: 24px; }
.logo { font-size: 18px; font-weight: 700; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link { padding: 6px 12px; border-radius: 6px; color: var(--text); text-decoration: none; font-weight: 500; transition: background .15s; }
.nav-link:hover { background: var(--bg); }
.nav-link.active { background: var(--primary); color: #fff; }
.logout { color: var(--text-muted); }
.logout:hover { color: var(--danger); background: #fef2f2; }
.nav-user { font-size: 13px; color: var(--text-muted); padding: 0 8px; }

/* Main */
.main { max-width: 1600px; margin: 0 auto; padding: 24px; }

/* Flash */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-weight: 500; }
.flash-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.flash-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.flash-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* Page header */
.page-header { margin-bottom: 20px; }
.page-title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Stats */
.stats-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { padding: 4px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.stat-active   { background: #dcfce7; color: #15803d; }
.stat-inactive { background: #f1f5f9; color: #64748b; }
.stat-expired  { background: #fef2f2; color: #b91c1c; }
.stat-total    { background: #eff6ff; color: #1d4ed8; }

/* Toolbar */
.toolbar { margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-input { width: 240px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color .15s; }
.filter-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.filter-select { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; background: var(--surface); color: var(--text); cursor: pointer; transition: border-color .15s; }
.filter-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.table thead tr { background: #f8fafc; }
.table th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: #64748b; border-bottom: 1px solid var(--border); user-select: none; }
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { background: #f1f5f9; color: var(--primary); }
.table th.sort-asc .sort-icon::after  { content: ' ↑'; }
.table th.sort-desc .sort-icon::after { content: ' ↓'; }
.sort-icon { color: var(--text-muted); font-size: 11px; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }

.td-domain { font-weight: 600; font-family: monospace; font-size: 13px; }
.td-target a { color: var(--primary); text-decoration: none; max-width: 220px; display: inline-block; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.td-target a:hover { text-decoration: underline; }
.td-comment { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.td-checked { white-space: nowrap; }
.td-actions { white-space: nowrap; display: flex; gap: 6px; }
.empty { text-align: center; padding: 40px; color: var(--text-muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.badge-active   { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-expired  { background: #fef2f2; color: #b91c1c; }
.badge-ok    { background: #dcfce7; color: #15803d; }
.badge-warn  { background: #fef9c3; color: #a16207; }
.badge-error { background: #fef2f2; color: #b91c1c; }
.badge-provisioning { background: #eff6ff; color: #1d4ed8; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* Column picker */
.col-picker-wrap { position: relative; }
.col-picker { display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 200; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.1); padding: 12px; min-width: 180px; }
.col-picker.open { display: block; }
.col-picker-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 8px; }
.col-picker-item { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.col-picker-item:hover { background: var(--bg); }
.col-picker-item input { width: 15px; height: 15px; cursor: pointer; accent-color: var(--primary); flex-shrink: 0; }
.col-picker-footer { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }

/* Checkboxes */
.th-check, .td-check { width: 36px; text-align: center; padding: 8px 4px; }
.th-check input, .td-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
tr.selected-row { background: #eff6ff !important; }

/* Metric values */
.metric { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Bulk action bar */
.bulk-bar { display: flex; align-items: center; gap: 12px; background: #1e40af; color: #fff; padding: 10px 16px; border-radius: var(--radius); margin-bottom: 10px; flex-wrap: wrap; }
.bulk-count { font-weight: 600; white-space: nowrap; }
.bulk-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bulk-tag-wrap { display: flex; gap: 6px; align-items: center; }
.bulk-tag-input { width: 140px; padding: 4px 8px; border-radius: 4px; border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.15); color: #fff; font-size: 13px; }
.bulk-tag-input::placeholder { color: rgba(255,255,255,.6); }
.bulk-bar .btn-secondary { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.3); }
.bulk-bar .btn-secondary:hover { background: rgba(255,255,255,.25); }
.bulk-bar .btn-danger { background: #dc2626; border-color: #b91c1c; }

/* Text helpers */
.muted  { color: var(--text-muted); }
.small  { font-size: 12px; }
.text-warn { color: var(--warn); font-weight: 600; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; border: 1px solid transparent; text-decoration: none; transition: background .15s, border-color .15s; line-height: 1; white-space: nowrap; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.login-logo { font-size: 32px; text-align: center; margin-bottom: 8px; }
.login-title { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 28px; }

/* Form */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 900px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.label { font-size: 13px; font-weight: 600; color: #475569; }
.required { color: var(--danger); }
.input { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; transition: border-color .15s; background: var(--surface); color: var(--text); }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.input:disabled { background: var(--bg); color: var(--text-muted); cursor: not-allowed; }
.textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.form-actions { display: flex; gap: 8px; }

/* Inline editable comment */
.td-editable { cursor: text; min-width: 120px; }
.td-editable:hover { background: #f8fafc; outline: 1px dashed var(--border); }
.td-editable.editing { outline: 2px solid var(--primary); background: #fff; border-radius: 3px; padding: 2px 6px; min-width: 160px; }
.td-editable.saved { background: #dcfce7; transition: background .4s; }

/* Provision banner */
.provision-banner { margin-top: 12px; padding: 10px 16px; border-radius: var(--radius); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.provision-banner-active { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; animation: pulse 1.5s ease-in-out infinite; }
.provision-banner-done   { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* Import page */
.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.section-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6; }
.section-desc code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.import-result { margin-bottom: 20px; border-radius: var(--radius); padding: 16px; }
.import-result pre { font-size: 13px; white-space: pre-wrap; word-break: break-word; margin: 0; }
.import-result-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.import-result-error   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }

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

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .filter-input { width: 100%; }
    .page-title-row { flex-direction: column; align-items: flex-start; }
}
