/* ═══════════════════════════════════════════════════════════
   PatrolWizzard V6 — Components
   ═══════════════════════════════════════════════════════════ */

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4); font-size: var(--text-sm);
    font-weight: 500; border-radius: var(--radius-md);
    border: 1px solid transparent; cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap; line-height: 1.4;
    text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: var(--sp-1) var(--sp-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--sp-3) var(--sp-6); font-size: var(--text-base); }
.btn-block { width: 100%; }

.btn-primary {
    background: var(--pw-primary); color: #fff; border-color: var(--pw-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--pw-primary-dark); }

.btn-secondary {
    background: var(--bg-card); color: var(--text-secondary);
    border-color: var(--border-default);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-body); border-color: var(--border-focus); }

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(0.9); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.9); }
.btn-warning { background: var(--color-warning); color: #fff; }
.btn-warning:hover:not(:disabled) { filter: brightness(0.9); }

.btn-ghost {
    background: transparent; color: var(--text-secondary); border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-body); color: var(--text-primary); }

.btn-icon {
    width: 34px; height: 34px; padding: 0;
    border-radius: var(--radius-md);
}

.btn .spinner {
    width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff; border-radius: 50%;
    animation: pw-spin 0.6s linear infinite;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--bg-card); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card-header {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 {
    font-size: var(--text-md); font-weight: 600; color: var(--text-primary);
}
.card-body { padding: var(--sp-5); }
.card-footer {
    padding: var(--sp-3) var(--sp-5);
    border-top: 1px solid var(--border-light);
    display: flex; align-items: center; justify-content: space-between;
}

/* ── Stat Cards ────────────────────────────────────────── */
.stats-grid {
    display: grid; gap: var(--sp-4);
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    margin-bottom: var(--sp-6);
}
.stat-card {
    background: var(--bg-card); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-label {
    font-size: var(--text-xs); color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500;
    margin-bottom: var(--sp-1);
}
.stat-card .stat-value {
    font-size: var(--text-2xl); font-weight: 700; color: var(--text-primary);
    letter-spacing: -0.5px;
}
.stat-card .stat-change {
    font-size: var(--text-xs); margin-top: var(--sp-1);
    display: flex; align-items: center; gap: var(--sp-1);
}
.stat-card .stat-change.up { color: var(--color-success); }
.stat-card .stat-change.down { color: var(--color-danger); }
.stat-card .stat-icon {
    width: 40px; height: 40px; border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: var(--sp-3);
}

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: var(--sp-4); }
.form-label {
    display: block; font-size: var(--text-sm); font-weight: 500;
    color: var(--text-primary); margin-bottom: var(--sp-1);
}
.form-label .required { color: var(--color-danger); margin-left: 2px; }
.form-hint {
    font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--sp-1);
}
.form-error {
    font-size: var(--text-xs); color: var(--color-danger); margin-top: var(--sp-1);
}
.form-input, .form-select, .form-textarea {
    width: 100%; padding: var(--sp-2) var(--sp-3);
    background: var(--bg-input); border: 1px solid var(--border-default);
    border-radius: var(--radius-md); font-size: var(--text-sm);
    color: var(--text-primary); transition: border-color var(--transition-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--pw-primary-50);
}
.form-input.error, .form-select.error, .form-textarea.error {
    border-color: var(--border-error);
    box-shadow: 0 0 0 3px var(--color-danger-bg);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { cursor: pointer; }

.form-row {
    display: grid; gap: var(--sp-4);
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.form-check {
    display: flex; align-items: center; gap: var(--sp-2); cursor: pointer;
}
.form-check input[type="checkbox"], .form-check input[type="radio"] {
    width: 16px; height: 16px; cursor: pointer; accent-color: var(--pw-primary);
}
.form-actions {
    display: flex; gap: var(--sp-2); justify-content: flex-end;
    padding-top: var(--sp-4); border-top: 1px solid var(--border-light);
    margin-top: var(--sp-4);
}

.input-group {
    display: flex; align-items: stretch;
}
.input-group .form-input { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.input-group .btn { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.input-group .input-prefix, .input-group .input-suffix {
    padding: var(--sp-2) var(--sp-3); background: var(--bg-body);
    border: 1px solid var(--border-default); color: var(--text-muted);
    font-size: var(--text-sm); display: flex; align-items: center;
}

/* ── Tables ────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%; border-collapse: collapse; font-size: var(--text-sm);
}
.data-table thead th {
    padding: var(--sp-3) var(--sp-4); text-align: left;
    font-size: var(--text-xs); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-muted); background: var(--bg-body);
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap; cursor: default;
    user-select: none;
}
.data-table thead th.sortable { cursor: pointer; }
.data-table thead th.sortable:hover { color: var(--text-primary); }
.data-table thead th .sort-icon { margin-left: var(--sp-1); opacity: 0.3; }
.data-table thead th.sort-asc .sort-icon,
.data-table thead th.sort-desc .sort-icon { opacity: 1; color: var(--pw-primary); }

.data-table tbody td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary); vertical-align: middle;
}
.data-table tbody tr:hover td { background: var(--pw-primary-50); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .cell-primary { color: var(--text-primary); font-weight: 500; }
.data-table .cell-mono { font-family: var(--font-mono); font-size: var(--text-xs); }
.data-table .cell-actions {
    display: flex; gap: var(--sp-1); justify-content: flex-end;
}

.table-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.table-toolbar .search-box {
    position: relative; flex: 1; max-width: 300px;
}
.table-toolbar .search-box input {
    width: 100%; padding: var(--sp-2) var(--sp-3) var(--sp-2) 34px;
    background: var(--bg-card); border: 1px solid var(--border-default);
    border-radius: var(--radius-md); font-size: var(--text-sm);
}
.table-toolbar .search-box .search-icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted);
}
.table-toolbar .filters { display: flex; gap: var(--sp-2); }

.table-pagination {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--sp-3) 0; font-size: var(--text-sm); color: var(--text-muted);
}
.table-pagination .page-buttons { display: flex; gap: var(--sp-1); }
.table-pagination .page-btn {
    width: 32px; height: 32px; border: 1px solid var(--border-light);
    background: var(--bg-card); border-radius: var(--radius-md);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: var(--text-sm); color: var(--text-secondary);
    transition: all var(--transition-fast);
}
.table-pagination .page-btn:hover { border-color: var(--pw-primary); color: var(--pw-primary); }
.table-pagination .page-btn.active {
    background: var(--pw-primary); border-color: var(--pw-primary); color: #fff;
}
.table-pagination .page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Badges ────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: var(--sp-1);
    padding: 2px 8px; border-radius: var(--radius-full);
    font-size: var(--text-xs); font-weight: 500;
    white-space: nowrap;
}
.badge-primary { background: var(--pw-primary-100); color: var(--pw-primary); }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-neutral {
    background: rgba(100,116,139,0.1); color: var(--text-secondary);
}
.badge-dot::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
}

/* ── Tabs ──────────────────────────────────────────────── */
.tabs {
    display: flex; gap: 0; border-bottom: 1px solid var(--border-light);
    margin-bottom: var(--sp-5);
}
.tab-btn {
    padding: var(--sp-3) var(--sp-4); font-size: var(--text-sm);
    color: var(--text-muted); background: none; border: none;
    border-bottom: 2px solid transparent; cursor: pointer;
    font-weight: 500; transition: all var(--transition-fast);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
    color: var(--pw-primary); border-bottom-color: var(--pw-primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: pw-fade-in 200ms ease; }

/* ── Alerts ────────────────────────────────────────────── */
.alert {
    padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md);
    font-size: var(--text-sm); display: flex; align-items: flex-start; gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}
.alert-info { background: var(--color-info-bg); color: var(--color-info); border: 1px solid rgba(59,130,246,0.2); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border: 1px solid rgba(16,185,129,0.2); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border: 1px solid rgba(245,158,11,0.2); }
.alert-danger { background: var(--color-danger-bg); color: var(--color-danger); border: 1px solid rgba(239,68,68,0.2); }

/* ── Empty State ───────────────────────────────────────── */
.empty-state {
    text-align: center; padding: var(--sp-12) var(--sp-6);
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: var(--sp-4); opacity: 0.3; }
.empty-state h3 { font-size: var(--text-md); color: var(--text-secondary); margin-bottom: var(--sp-2); }
.empty-state p { font-size: var(--text-sm); margin-bottom: var(--sp-4); }

/* ── Loading ───────────────────────────────────────────── */
.loading-spinner {
    display: flex; align-items: center; justify-content: center;
    padding: var(--sp-10);
}
.loading-spinner::after {
    content: ''; width: 32px; height: 32px;
    border: 3px solid var(--border-light);
    border-top-color: var(--pw-primary); border-radius: 50%;
    animation: pw-spin 0.7s linear infinite;
}
.skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, #e8ecf1 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: pw-pulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

/* ── Dropdown ──────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; top: calc(100% + 4px); right: 0;
    background: var(--bg-card); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    min-width: 180px; z-index: 50; display: none;
    animation: pw-scale-in 150ms ease;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4); font-size: var(--text-sm);
    color: var(--text-secondary); cursor: pointer; transition: all var(--transition-fast);
}
.dropdown-item:hover { background: var(--pw-primary-50); color: var(--pw-primary); }
.dropdown-item:first-child { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.dropdown-item:last-child { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.dropdown-divider { height: 1px; background: var(--border-light); margin: var(--sp-1) 0; }

/* ── Tooltip ───────────────────────────────────────────── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute; bottom: calc(100% + 6px); left: 50%;
    transform: translateX(-50%); padding: 4px 8px;
    background: var(--bg-tooltip); color: #fff;
    font-size: var(--text-xs); border-radius: var(--radius-sm);
    white-space: nowrap; opacity: 0; pointer-events: none;
    transition: opacity var(--transition-fast);
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── Avatar ────────────────────────────────────────────── */
.avatar {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    font-size: var(--text-xs); font-weight: 600; flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: var(--text-sm); }
.avatar-xl { width: 56px; height: 56px; font-size: var(--text-lg); }

/* ── Utility ───────────────────────────────────────────── */
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-4 { gap: var(--sp-4); }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.hidden { display: none !important; }
