/*
 * Secure Portal - Base Layout (uses CSS variables only)
 * Load a theme-*.css file BEFORE this file to apply a theme.
 */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--font-primary); background-color: var(--bg-body); color: var(--text-dark); line-height: 1.6; font-size: 14px; }
a { color: var(--primary-color); text-decoration: none; transition: all 0.25s ease; }
a:hover { color: var(--primary-hover); }

/* ===== NAVBAR ===== */
/* 3-zone layout: hamburger pinned left, brand truly centered (absolute, so it
   ignores the widths of the side zones), user actions pinned right. */
.navbar { background: var(--navbar-bg); color: var(--navbar-text); padding: 0 16px; display: flex; justify-content: space-between; align-items: center; height: 60px; position: sticky; top: 0; z-index: 1000; box-shadow: var(--shadow-md); }
.navbar-brand { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }
.navbar-user { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.user-info { display: none; text-align: right; font-size: 12px; }
.user-info strong { display: block; font-size: 14px; }
.btn-logout { background: var(--logout-bg); color: var(--navbar-text); border: 1px solid var(--logout-border); padding: 6px 14px; border-radius: var(--radius); cursor: pointer; font-size: 12px; font-weight: 500; transition: all 0.25s ease; }
.btn-logout:hover { background: var(--logout-hover); }
.menu-toggle { background: none; border: none; color: var(--navbar-text); font-size: 24px; cursor: pointer; display: block; padding: 8px; order: -1; }

/* ===== SIDEBAR ===== */
.sidebar { position: fixed; left: -250px; top: 60px; width: 250px; height: calc(100vh - 60px); background: var(--sidebar-bg); color: var(--sidebar-text); padding: 12px 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; transition: left 0.3s ease; z-index: 999; border-right: 1px solid var(--sidebar-border); box-shadow: 4px 0 15px rgba(0,0,0,0.1); }
@supports (height: 100dvh) {
    .sidebar { height: calc(100dvh - 60px); }
}
.sidebar.active { left: 0; }
.sidebar a { display: block; padding: 11px 16px; color: var(--sidebar-link); text-decoration: none; transition: all 0.25s ease; font-size: 13px; border-left: 3px solid transparent; font-weight: 500; }
.sidebar a:hover { background: var(--sidebar-hover); color: var(--sidebar-hover-text); padding-left: 20px; }
.sidebar a.active { background: var(--sidebar-active-bg); border-left-color: var(--sidebar-active-border); color: var(--sidebar-active-text); }
.sidebar-section { padding: 8px 0; border-top: 1px solid var(--sidebar-border); margin-top: 8px; }
.sidebar-section:first-child { border-top: none; margin-top: 0; }
.sidebar-title { padding: 8px 16px; font-size: 10px; color: var(--sidebar-title); text-transform: uppercase; font-weight: 700; letter-spacing: 1px; }

/* ===== MAIN CONTENT ===== */
.main-content { padding: 16px; padding-bottom: 120px; min-height: calc(100vh - 60px); }
.container { max-width: 1200px; margin: 0 auto; }
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 10px 16px; font-size: 12.5px; color: var(--text-muted); background: transparent; }
.breadcrumb a { color: var(--primary-color); text-decoration: none; font-weight: 600; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .breadcrumb-sep { color: var(--text-muted); opacity: 0.6; }
.breadcrumb .breadcrumb-current { color: var(--text-dark); font-weight: 600; }
.page-title { font-size: 26px; font-weight: 700; color: var(--text-dark); margin-bottom: 6px; letter-spacing: -0.5px; }
.page-subtitle { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }

/* ===== CARDS ===== */
.card, .form-card, .table-container, .permissions-section, .roles-list, .stat-card, .action-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 16px;
    transition: all 0.25s ease;
}
.card:hover, .form-card:hover, .stat-card:hover, .action-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card, .form-card, .permissions-section { padding: 20px; }
.stat-card { padding: 8px 12px; border-top: 3px solid var(--primary-color); }
.stat-card-link { display: block; text-decoration: none; color: inherit; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.stat-card-link:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-top-color: var(--secondary-color); }
.stat-value { font-size: 16px; font-weight: 700; color: var(--primary-color); margin-bottom: 2px; }
.stat-label { color: var(--text-muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.card-title { font-size: 16px; font-weight: 700; color: var(--text-dark); margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--card-border); }
.action-card { display: block; padding: 16px; text-align: center; text-decoration: none; color: inherit; cursor: pointer; }
.action-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.action-icon { font-size: 32px; margin-bottom: 10px; }
.action-title { font-size: 14px; font-weight: 600; color: var(--text-dark); margin-bottom: 4px; }
.action-description { font-size: 12px; color: var(--text-muted); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 6px; color: var(--text-dark); font-weight: 600; font-size: 13px; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--input-border);
    border-radius: var(--radius); font-size: 14px; font-family: inherit;
    transition: all 0.25s ease; -webkit-appearance: none; appearance: none;
    background-color: var(--input-bg); color: var(--text-dark);
}
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="tel"]:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px var(--input-focus-ring); }
input:disabled { background: var(--input-disabled-bg); color: var(--text-muted); cursor: not-allowed; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%23999' d='M5 7L1 3h8z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; cursor: pointer; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== BUTTONS ===== */
.btn { padding: 10px 18px; border: none; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.25s ease; display: inline-block; text-decoration: none; text-align: center; white-space: nowrap; user-select: none; touch-action: manipulation; }
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-text); border: 1px solid var(--btn-primary-border); }
.btn-primary:hover { background: var(--btn-primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-text); border: 1px solid var(--btn-secondary-border); }
.btn-secondary:hover { background: var(--btn-secondary-hover); }
.btn-edit { background: var(--btn-edit-bg); color: white; padding: 5px 12px; font-size: 12px; border: none; border-radius: var(--radius); cursor: pointer; }
.btn-edit:hover { opacity: 0.85; }
.btn-delete { background: var(--btn-delete-bg); color: white; padding: 5px 12px; font-size: 12px; border: none; border-radius: var(--radius); cursor: pointer; }
.btn-delete:hover { opacity: 0.85; }
.btn-create { display: inline-block; padding: 10px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center; white-space: nowrap; transition: all 0.25s ease; background: var(--btn-primary-bg); color: var(--btn-primary-text); border: 1px solid var(--btn-primary-border); }
.btn-create:hover { background: var(--btn-primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-create-invoice { display:block; width:100%; padding:14px; background:var(--primary-color); color:#fff; text-align:center; text-decoration:none; border-radius:8px; font-size:15px; font-weight:700; letter-spacing:0.5px; margin-bottom:10px; box-shadow:0 2px 8px rgba(0,0,0,0.1); transition:opacity 0.2s, transform 0.2s; box-sizing:border-box; }
.btn-create-invoice:hover { opacity:0.9; transform:translateY(-1px); }

/* ===== ALERTS ===== */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; border-left: 4px solid; }
.alert-success { background: var(--success-bg); color: var(--success-text); border-left-color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger-text); border-left-color: var(--danger); }
.alert-info { background: var(--info-bg); color: var(--info-text); border-left-color: var(--info); }
.alert ul { margin: 6px 0 0 18px; }
.alert li { margin: 3px 0; }

/* ===== TABLES ===== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--table-head-bg); border-bottom: 2px solid var(--card-border); }
th { padding: 11px 14px; text-align: left; font-weight: 700; color: var(--text-dark); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 11px 14px; border-bottom: 1px solid var(--card-border); color: var(--text-dark); }
tbody tr { transition: background 0.2s ease; }
tbody tr:hover { background: var(--table-row-hover); }

/* ===== PAGINATION ===== */
.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 20px; margin-bottom: 16px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border: 1px solid var(--card-border); border-radius: var(--radius); text-decoration: none; color: var(--primary-color); font-size: 12px; font-weight: 500; transition: all 0.2s; }
.pagination a:hover, .pagination .active { background: var(--btn-primary-bg); color: var(--btn-primary-text); border-color: var(--primary-color); }

/* ===== CONTROLS ===== */
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; margin-bottom: 16px; flex-wrap: wrap; }
.form-actions .btn { min-width: 100px; }
.action-buttons { display: flex; gap: 6px; }
.page-controls { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.search-box { width: 100%; }
.search-box input { width: 100%; }

/* ===== CHECKBOXES & PERMISSIONS ===== */
.permission-item { display: flex; align-items: flex-start; cursor: pointer; padding: 10px; background: var(--input-bg); border-radius: var(--radius); margin-bottom: 6px; border: 1px solid var(--card-border); transition: background 0.2s; }
.permission-item:hover { background: var(--table-row-hover); }
.permission-item input[type="checkbox"] { margin-right: 10px; margin-top: 2px; width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary-color); }
.permission-details { flex: 1; }
.permission-name { font-weight: 600; color: var(--text-dark); font-size: 13px; margin-bottom: 2px; }
.permission-description { font-size: 12px; color: var(--text-muted); }
.permission-group { margin-bottom: 20px; }
.permission-group-title { font-size: 10px; color: var(--text-muted); text-transform: uppercase; font-weight: 700; letter-spacing: 0.5px; margin-bottom: 8px; }
.checkbox-group { padding: 10px; background: var(--input-bg); border-radius: var(--radius); border: 1px solid var(--card-border); }
.checkbox-item { display: flex; align-items: center; margin: 6px 0; cursor: pointer; }
.checkbox-item input[type="checkbox"] { margin-right: 10px; cursor: pointer; accent-color: var(--primary-color); }
.checkbox-item label { margin: 0; cursor: pointer; font-size: 14px; color: var(--text-dark); }

/* ===== PROFILE INFO ===== */
.info-group { margin-bottom: 14px; padding: 12px; background: var(--input-bg); border-radius: var(--radius); border: 1px solid var(--card-border); }
.info-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; margin-bottom: 4px; }
.info-value { font-size: 15px; font-weight: 500; color: var(--text-dark); }

/* ===== LOGIN PAGE ===== */
.login-page-bg { min-height: calc(100vh - 160px); display: flex; justify-content: center; align-items: center; padding: 16px; background: var(--login-bg); }
.login-container { background: var(--card-bg); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); width: 100%; max-width: 420px; padding: 32px 28px; border: 1px solid var(--card-border); }
.logo { text-align: center; margin-bottom: 24px; }
.logo h1 { color: var(--text-dark); font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.logo p { color: var(--text-muted); font-size: 13px; }
.demo-credentials { background: var(--info-bg); border: 1px solid var(--info); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 12px; }
.demo-credentials p { margin: 5px 0; color: var(--info-text); }
.demo-credentials code { background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 3px; font-family: monospace; }
.btn-login { width: 100%; padding: 12px; background: var(--btn-primary-bg); color: var(--btn-primary-text); border: 1px solid var(--btn-primary-border); border-radius: var(--radius); font-size: 15px; font-weight: 700; cursor: pointer; transition: all 0.25s; }
.btn-login:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.password-requirements { background: var(--input-bg); border: 1px solid var(--card-border); border-radius: var(--radius); padding: 14px; margin-top: 14px; font-size: 12px; color: var(--text-muted); }
.requirement { margin: 6px 0; padding-left: 18px; position: relative; }
.requirement:before { content: '✓'; position: absolute; left: 0; color: var(--success); font-weight: bold; }

/* ===== ROLES LIST ===== */
.roles-list-title { padding: 14px 16px; background: var(--table-head-bg); border-bottom: 1px solid var(--card-border); font-weight: 700; color: var(--text-dark); font-size: 13px; }
.role-item { padding: 12px 16px; border-bottom: 1px solid var(--card-border); cursor: pointer; transition: background 0.2s; }
.role-item:hover { background: var(--table-row-hover); }
.role-item.active { background: var(--sidebar-active-bg); border-left: 3px solid var(--primary-color); }
.role-name { font-weight: 600; color: var(--text-dark); margin-bottom: 3px; font-size: 14px; }
.role-count { font-size: 12px; color: var(--text-muted); }

/* ===== STATUS BADGES ===== */
.user-active { background: var(--success-bg); color: var(--success-text); padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.user-inactive { background: var(--danger-bg); color: var(--danger-text); padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }

/* ===== MISC ===== */
.no-permission { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.page-layout { display: block; }
.info-box { background: var(--info-bg); border-left: 4px solid var(--info); color: var(--info-text); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.action-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 16px; }
.section-title { font-size: 18px; font-weight: 700; color: var(--text-dark); margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid var(--card-border); }

/* ===== THEME SWATCH ===== */
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }
.theme-swatch { border: 2px solid var(--card-border); border-radius: var(--radius); padding: 10px; cursor: pointer; transition: all 0.2s; }
.theme-swatch:hover { border-color: var(--primary-color); }
.theme-swatch.selected { border-color: var(--primary-color); box-shadow: 0 0 0 3px var(--input-focus-ring); }
.theme-swatch-preview { height: 36px; border-radius: 4px; margin-bottom: 6px; }
.theme-swatch-name { font-size: 12px; font-weight: 600; color: var(--text-dark); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: var(--primary-color); border-radius: 3px; opacity: 0.5; }

/* ===== DESKTOP ===== */
@media (min-width: 641px) {
    .navbar { padding: 0 24px; height: 70px; }
    .navbar-brand { font-size: 20px; }
    .menu-toggle { display: block; }
    .user-info { display: block; }
    .sidebar { left: 0; top: 70px; height: calc(100vh - 70px); box-shadow: none; }
    @supports (height: 100dvh) {
        .sidebar { height: calc(100dvh - 70px); }
    }
    /* On desktop the sidebar is open by default; toggling adds .active to COLLAPSE it
       (the same class the mobile off-canvas sidebar uses to OPEN) */
    .sidebar.active { left: -250px; }
    .main-content { margin-left: 250px; margin-top: 70px; padding: 24px; padding-bottom: 70px; min-height: calc(100vh - 70px); transition: margin-left 0.3s ease; }
    .sidebar.active ~ .main-content { margin-left: 0; }
    .main-content .app-footer { left: 250px; }
    .sidebar.active ~ .main-content .app-footer { left: 0; }
    .page-title { font-size: 30px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .action-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
    .page-controls { flex-direction: row; justify-content: space-between; align-items: center; }
    .search-box { max-width: 280px; }
    .page-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
    .theme-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ===== MOBILE ===== */
@media (max-width: 640px) {
    .main-content { padding: 12px; padding-bottom: 120px; }
    .page-title { font-size: 20px; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .btn-create { width: 100%; }
    .action-buttons { flex-direction: column; }
    .btn-edit, .btn-delete { width: 100%; }
    th:nth-child(5), td:nth-child(5) { display: none; }
}

@media print {
    .navbar, .sidebar, .btn-logout, .form-actions, .app-footer { display: none; }
    .main-content { margin: 0; padding: 0; }
}

/* ===== GLASS THEME EXTRAS ===== */
/* Applied only when glass theme active — backdrop-filter needs explicit elements */
.sidebar { backdrop-filter: blur(0px); }
.card, .form-card { backdrop-filter: blur(0px); }

/* Body background — themes set --bg-body as gradient or color */
body { background: var(--bg-body); }

/* Login page — full screen centered */
body.login-page { padding-top: 70px; padding-bottom: 90px; }
/* Login page footer sits above the top bar's z-index isn't a concern (they're
   pinned to opposite edges), but bump z-index for consistency with the topbar. */
body.login-page .app-footer { z-index: 1000; }

/* ===== LOGIN PAGE TOP BAR ===== */
.login-topbar { position: fixed; top: 0; left: 0; right: 0; min-height: 44px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 6px 18px; background: var(--navbar-bg); color: var(--navbar-text); font-size: 12px; font-weight: 500; z-index: 1000; }
.login-topbar .login-flag { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#topHeaderDateTime { white-space: nowrap; }

/* ===== FOOTER ===== */
/* Fixed to the bottom of the viewport on every page so it never scrolls with
   content; offset from the left on desktop to sit clear of the sidebar
   (collapses back to full width when the sidebar itself is collapsed).
   .main-content reserves generous bottom padding so content is never hidden
   behind it, even if the text wraps to multiple lines on a narrow phone. */
.app-footer { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 24px; text-align: center; min-height: 40px; padding: 8px 16px; line-height: 1.35; color: var(--text-muted); font-size: 12px; border-top: 1px solid var(--card-border); background: var(--card-bg); position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; }
.app-footer a { color: var(--text-muted); text-decoration: underline; }

/* ===== NAVBAR LOGO LINK ===== */
.navbar-brand a {
    color: var(--navbar-text);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: -0.5px;
    transition: opacity 0.2s ease;
}
.navbar-brand a:hover {
    opacity: 0.85;
    color: var(--navbar-text);
}
