/* Netora UI components */

/* ── Buttons ───────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 22px;
    border-radius: var(--r-sm);
    font-size: .95rem;
    font-weight: 600;
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: all .18s ease;
    font-family: inherit;
    line-height: 1.2;
    text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn.disabled { opacity: .6; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); box-shadow: var(--shadow-green); color: #fff; }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-2); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-warn { background: var(--warn); color: #fff; border-color: var(--warn); }

.btn-outline { background: transparent; color: var(--brand-dark); border-color: var(--brand); }
.btn-outline:hover { background: var(--brand-light); }

.btn-sm { padding: 7px 14px; font-size: .85rem; }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-xl { padding: 18px 36px; font-size: 1.1rem; }

.btn-block { width: 100%; }
.btn-icon { padding: 9px; width: 38px; height: 38px; border-radius: var(--r-sm); }

.btn-group { display: inline-flex; gap: 8px; flex-wrap: wrap; }

/* ── Forms ─────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.label {
    display: block;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 8px;
}
.label .required { color: var(--danger); margin-right: 4px; }

.input, .select, .textarea {
    width: 100%;
    padding: 12px 14px;
    font-family: inherit;
    font-size: .95rem;
    border: 1px solid var(--border-2);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(34,197,94,.15);
}
.input::placeholder, .textarea::placeholder { color: var(--text-mute); }
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.select {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2397a299' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: left 14px center;
    padding-left: 38px;
}

.input-group { position: relative; }
.input-group .input { padding-right: 42px; }
.input-group .input-icon {
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    color: var(--text-mute);
    pointer-events: none;
    width: 18px; height: 18px;
}
.input-group .toggle-pw {
    position: absolute; top: 50%; left: 14px; transform: translateY(-50%);
    cursor: pointer; background: transparent; border: 0; color: var(--text-mute); padding: 4px;
}

.help-text { font-size: .8rem; color: var(--text-3); margin-top: 6px; }

/* Checkbox / radio */
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .95rem; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

/* ── Cards ─────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 22px;
    box-shadow: var(--shadow-sm);
}
.card.flat { box-shadow: none; }
.card-hover { transition: transform .15s, box-shadow .15s; }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1.1rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 10px; }
.card-subtitle { font-size: .85rem; color: var(--text-3); margin-top: 4px; }

/* Hero card with gradient */
.hero-card {
    background: linear-gradient(135deg, var(--green-600), var(--green-800));
    color: #fff;
    border-radius: var(--r-md);
    padding: 28px 32px;
    position: relative;
    overflow: hidden;
}
.hero-card::after {
    content: '';
    position: absolute;
    top: -50px; left: -50px;
    width: 300px; height: 300px;
    background: radial-gradient(circle, rgba(255,255,255,.08), transparent 70%);
}
.hero-card h2 { color: #fff; margin: 0 0 4px; font-size: 1.6rem; position: relative; }
.hero-card p { color: rgba(255,255,255,.85); margin: 0; position: relative; }

/* ── Alerts ────────────────────────────────── */
.alert {
    padding: 14px 18px;
    border-radius: var(--r-sm);
    margin-bottom: 16px;
    border: 1px solid;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}
.alert-success { background: var(--green-50); border-color: var(--green-200); color: var(--green-800); }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* ── Badges ────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: .75rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text-2);
}
.badge-success { background: var(--green-100); color: var(--green-800); }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-purple  { background: #ede9fe; color: #5b21b6; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ── Tables ────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 14px 16px; text-align: right; border-bottom: 1px solid var(--border); font-size: .9rem; }
.table th { color: var(--text-3); font-weight: 600; background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:hover { background: var(--brand-bg); }
.table tbody tr:last-child td { border-bottom: 0; }

/* ── Stat cards ────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.stat-card-icon {
    width: 44px; height: 44px;
    border-radius: var(--r-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-light);
    color: var(--brand-dark);
    margin-bottom: 12px;
}
.stat-card-value { font-size: 1.8rem; font-weight: 800; color: var(--text); line-height: 1.1; }
.stat-card-label { font-size: .85rem; color: var(--text-3); margin-top: 4px; }
.stat-card.accent-green .stat-card-icon { background: var(--green-100); color: var(--green-700); }
.stat-card.accent-blue  .stat-card-icon { background: #dbeafe; color: #1e40af; }
.stat-card.accent-orange .stat-card-icon { background: #ffedd5; color: #c2410c; }
.stat-card.accent-purple .stat-card-icon { background: #ede9fe; color: #6d28d9; }
.stat-card.accent-pink  .stat-card-icon { background: #fce7f3; color: #be185d; }

/* ── Modal ─────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15,29,20,.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: calc(100% - 32px);
    max-height: 90vh;
    overflow: auto;
    animation: modalin .2s ease;
}
@keyframes modalin { from { opacity: 0; transform: translateY(10px) scale(.98);} to { opacity: 1; transform: translateY(0) scale(1);} }
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { margin: 0; }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}
.modal-close {
    background: transparent;
    border: 0;
    cursor: pointer;
    color: var(--text-3);
    width: 32px; height: 32px;
    border-radius: var(--r-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

/* ── Tabs ──────────────────────────────────── */
.tabs {
    display: inline-flex;
    background: var(--surface-2);
    padding: 4px;
    border-radius: var(--r-sm);
    gap: 4px;
    border: 1px solid var(--border);
}
.tab {
    padding: 8px 16px;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    font-size: .9rem;
    font-weight: 600;
    border: 0;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.tab:hover { background: var(--surface); }
.tab.active { background: var(--surface); color: var(--brand-darker); box-shadow: var(--shadow-sm); }

/* ── Empty state ───────────────────────────── */
.empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-3);
}
.empty-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--surface-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--text-mute);
}
.empty h3 { color: var(--text); margin-bottom: 8px; }

/* ── Pagination ────────────────────────────── */
.pagination { display: inline-flex; gap: 4px; margin-top: 16px; }
.pagination a, .pagination span {
    padding: 8px 12px;
    border-radius: var(--r-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: .9rem;
    min-width: 38px;
    text-align: center;
}
.pagination a:hover { background: var(--brand-bg); border-color: var(--brand); color: var(--brand-dark); }
.pagination .active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ── Utilities ─────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }

.grid { display: grid; }
.grid-2 { grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.grid-auto-sm { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }

.rounded { border-radius: var(--r-md); }
.rounded-full { border-radius: 50%; }

/* ── Responsive ───────────────────────────── */
@media (max-width: 768px) {
    .form-row, .form-row-3 { grid-template-columns: 1fr; gap: 12px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .grid-auto, .grid-auto-sm { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

    .card { padding: 16px; border-radius: var(--r); }
    .card-header { margin-bottom: 12px; padding-bottom: 12px; flex-wrap: wrap; gap: 10px; }
    .card-title { font-size: 1rem; }

    .hero-card { padding: 18px 20px; border-radius: var(--r); }
    .hero-card h2 { font-size: 1.2rem; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
    .stat-card { padding: 14px; }
    .stat-card-icon { width: 38px; height: 38px; margin-bottom: 8px; }
    .stat-card-value { font-size: 1.4rem; }
    .stat-card-label { font-size: .78rem; }

    .table th, .table td { padding: 10px 12px; font-size: .85rem; }
    .table th { font-size: .72rem; padding: 8px 12px; }

    .modal { width: calc(100% - 16px); max-height: 92vh; border-radius: var(--r); }
    .modal-header { padding: 14px 16px; }
    .modal-body { padding: 16px; }
    .modal-footer { padding: 12px 16px; flex-wrap: wrap; }

    .btn { padding: 10px 16px; font-size: .9rem; }
    .btn-lg, .btn-xl { padding: 12px 20px; font-size: .95rem; }
    .btn-group { gap: 6px; }
    .btn-group .btn-block-mobile { width: 100%; }

    .input, .select, .textarea { font-size: 16px; padding: 11px 12px; } /* 16px prevents iOS zoom */
    .select { padding-left: 34px; background-position: left 12px center; }

    .tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { padding: 7px 12px; font-size: .85rem; white-space: nowrap; }

    .pagination { flex-wrap: wrap; gap: 3px; }
    .pagination a, .pagination span { padding: 6px 10px; min-width: 34px; font-size: .85rem; }

    .empty { padding: 36px 16px; }
    .empty-icon { width: 60px; height: 60px; margin-bottom: 12px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .card { padding: 14px; }
    .card-header { padding-bottom: 10px; margin-bottom: 10px; }
    .modal-footer { gap: 8px; }
    .modal-footer .btn { flex: 1; min-width: 0; }
    .alert { padding: 12px 14px; font-size: .88rem; }
    .badge { font-size: .7rem; padding: 2px 8px; }
}

/* Always-on horizontal scroll for tables on touch screens */
.table-wrap { -webkit-overflow-scrolling: touch; }

/* Defensive: collapse inline 2-col/3-col grids on phone */
@media (max-width: 768px) {
    .grid[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

/* Larger tap targets on coarse-pointer devices (phones/tablets) */
@media (hover: none) and (pointer: coarse) {
    .btn { min-height: 40px; }
    .btn-sm { min-height: 36px; }
    .check input { width: 22px; height: 22px; }
    .pagination a, .pagination span { min-width: 40px; min-height: 36px; padding: 8px 12px; }
    .tab { min-height: 36px; }
    .modal-close { width: 38px; height: 38px; }
    /* Ensure focused inputs don't get hidden behind soft keyboards */
    .input, .textarea, .select { font-size: 16px; }
}

/* Stack action rows on phones */
@media (max-width: 540px) {
    .btn-group { width: 100%; }
    .btn-group .btn { flex: 1 1 auto; min-width: 0; }
    .page-title-row .page-actions { width: 100%; }
    .page-title-row .page-actions .btn { flex: 1 1 auto; }
}
