/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #5f50e4;
    --primary-hover: #4e3fd3;
    --primary-light: #ebe9fc;
    --bg: #ffffff;
    --bg-gray: #f7f7fb;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --sidebar-w: 250px;
    --transition: 0.2s ease;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Auth Pages === */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-gray);
    padding: 20px;
}
.auth-card {
    background: var(--bg);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 40px;
    width: 100%;
    max-width: 480px;
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
}
.logo-icon {
    color: var(--primary);
    font-size: 24px;
}
.logo-text {
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
}
.auth-title {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 24px;
}
.auth-form .form-group { margin-bottom: 16px; }
.auth-form label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text);
}
.auth-link {
    text-align: center;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

/* === Form Elements === */
input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="url"],
select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: border-color var(--transition);
    outline: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
textarea { resize: vertical; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-grid .full-width { grid-column: 1 / -1; }
.form-grid .form-group { margin-bottom: 0; }
.form-actions {
    display: flex;
    gap: 10px;
    padding-top: 8px;
}
.field-error {
    color: #dc2626;
    font-size: 12px;
    margin-top: 2px;
    display: block;
}
.form-errors { margin-bottom: 12px; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    height: 40px;
}
.btn-outline:hover { background: var(--primary-light); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* === Dashboard Layout === */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 10;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
    flex-direction: column;
}
.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}
.sidebar-balance {
    display: flex;
    flex-direction: column;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.balance-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.balance-amount { font-size: 22px; font-weight: 700; color: var(--primary); margin-top: 2px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
    border-left: 3px solid transparent;
}
.nav-item:hover {
    background: var(--bg-gray);
    color: var(--text);
    text-decoration: none;
}
.nav-item.active {
    color: var(--primary);
    background: var(--primary-light);
    border-left-color: var(--primary);
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    background: var(--bg-gray);
    min-height: 100vh;
    max-width: stretch;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.page-title { font-size: 20px; font-weight: 600; }
.topbar-user { font-size: 14px; color: var(--primary);text-transform: uppercase; font-weight: 700; }
.content-area { padding: 24px 32px; }

/* === Stat Cards === */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 4px;
}

/* === Cards === */
.card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}
.card-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* === Tables === */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
thead { background: var(--bg-gray); }
th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}
tbody tr:hover { background: var(--bg-gray); }
tbody tr:last-child td { border-bottom: none; }
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}
.link-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-text { font-family: monospace; font-size: 13px; color: var(--primary); }

/* === URL cell with copy button === */
.url-cell {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 240px;
}
.url-truncate {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}
.copy-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 3px 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition), background var(--transition);
    line-height: 1;
}
.copy-btn:hover { color: var(--primary); background: var(--primary-light); }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dbeafe; color: #1e40af; }
.badge-paid { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-on_hold { background: #fef3c7; color: #92400e; }
.badge-deleted { background: #fee2e2; color: #991b1b; }
.badge-fraud { background: #fce7f3; color: #9d174d; }

/* === Inline Form === */
.inline-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}
.inline-form .form-group { margin-bottom: 0; flex: 1; max-width: 280px; }
.text-muted { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; }

/* === Link Preview === */
.link-preview-box {
    background: var(--bg-gray);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-top: 16px;
}
.link-preview-box.short-link-box { background: #f0eefa; border-color: #d4d0f3; }
.preview-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.link-preview-url {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--primary);
    word-break: break-all;
    line-height: 1.5;
}
.short-link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.short-link-text { flex: 1; }

/* === Delete Button === */
.delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.delete-btn:hover {
    color: #dc2626;
    background: #fee2e2;
}
.btn-danger {
    background: #dc2626;
    color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

/* === Modal — visibility is controlled entirely via JS inline style === */
.modal-overlay {
    /* display is set by JS: 'none' by default, 'flex' when open */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
.modal-card {
    background: var(--bg);
    border-radius: 12px;
    padding: 32px;
    max-width: 440px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    text-align: center;
    position: relative;
    z-index: 10000;
}
.modal-icon { margin-bottom: 16px; }
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.modal-text { font-size: 14px; color: var(--text-muted); line-height: 1.6; margin-bottom: 24px; }
.modal-text strong { color: var(--text); }
.modal-actions { display: flex; justify-content: center; gap: 10px; }

/* === Archived Table === */
.archived-title {
    color: #9ca3af;
    font-size: 15px;
    margin-bottom: 12px;
}
.archived-table {
    opacity: 0.7;
}
.archived-table thead { background: #f3f4f6; }
.badge-archived { background: #f3f4f6; color: #6b7280; }

/* === Toasts === */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 3s forwards;
    max-width: 380px;
}
.toast-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.toast-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.toast-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

@keyframes slideIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { width: 100%; position: relative; border-right: none; border-bottom: 1px solid var(--border); }
    .dashboard-layout { flex-direction: column; }
    .main-content { margin-left: 0; }
    .sidebar-nav { display: flex; overflow-x: auto; padding: 8px; }
    .nav-item { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; padding: 8px 16px; }
    .nav-item.active { border-left-color: transparent; border-bottom-color: var(--primary); }
    .sidebar-footer { display: none; }
    .content-area { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .form-row, .form-grid, .card-row { grid-template-columns: 1fr; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form .form-group { max-width: 100%; }
    .stat-cards { grid-template-columns: 1fr 1fr; }
}
