/* ============================================================
   PL kế toán - Design System
   ============================================================ */
:root {
    /* Brand colors - PL blue */
    --primary: #005baa;
    --primary-dark: #004785;
    --primary-light: #e6f0fa;
    --primary-lighter: #f0f6fc;
    --accent: #1e9bff;
    --accent-dark: #0a84d8;

    /* Semantic */
    --success: #2eb85c;
    --success-bg: #e8f7ee;
    --warning: #f5a623;
    --warning-bg: #fff5e0;
    --danger: #e74c3c;
    --danger-bg: #fdecea;
    --info: #17a2b8;
    --info-bg: #e0f7fa;

    /* Neutrals */
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #e4e7ed;
    --border-light: #ebeef5;
    --text: #2c3e50;
    --text-secondary: #5a6c7d;
    --text-muted: #8995a5;
    --text-light: #aab4c0;

    /* Layout */
    --sidebar-width: 248px;
    --sidebar-collapsed: 64px;
    --topbar-height: 60px;
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

    --font: 'Segoe UI', Roboto, 'Helvetica Neue', system-ui, -apple-system, Arial, sans-serif;

    --transition: 0.2s ease;
}

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

html, body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea {
    font-family: inherit; font-size: 14px;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    width: 100%;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--surface);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(30,155,255,0.12);
}
label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }

/* ============ APP LAYOUT ============ */
.app { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #005baa 0%, #004a8a 100%);
    color: #cfe3f6;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    height: var(--topbar-height);
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { color: #fff; font-size: 18px; font-weight: 300; letter-spacing: 0.5px; }
.logo-text strong { font-weight: 700; }
.sidebar-toggle { color: rgba(255,255,255,0.7); display: none; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 0;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

.nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.45);
    padding: 14px 20px 6px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #d6e6f5;
    font-size: 14px;
    transition: all var(--transition);
    border-left: 3px solid transparent;
    white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active {
    background: rgba(255,255,255,0.14);
    color: #fff;
    border-left-color: #1e9bff;
    font-weight: 500;
}
.nav-icon { display: flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex-shrink: 0; opacity: 0.9; }
.nav-label { flex: 1; }
.nav-arrow { font-size: 11px; transition: transform var(--transition); opacity: 0.7; }
.nav-group.open .nav-arrow { transform: rotate(180deg); }

.nav-children { max-height: 0; overflow: hidden; transition: max-height 0.25s ease; }
.nav-group.open .nav-children { max-height: 400px; }
.nav-child {
    padding: 8px 20px 8px 52px;
    font-size: 13px;
    color: #b9d4ee;
}
.nav-child:hover { color: #fff; background: rgba(255,255,255,0.06); }
.nav-dot { width: 5px; height: 5px; border-radius: 50%; background: rgba(255,255,255,0.4); flex-shrink: 0; }
.nav-child.active { color: #fff; font-weight: 500; }
.nav-child.active .nav-dot { background: #1e9bff; }

.sidebar-footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.1); flex-shrink: 0; }
.version { font-size: 11px; color: rgba(255,255,255,0.5); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

/* MAIN */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left var(--transition);
}

/* TOPBAR */
.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.topbar-center { flex: 1; max-width: 480px; }

.company-switcher { display: flex; align-items: center; gap: 8px; color: var(--primary); }
.company-info { line-height: 1.2; }
.company-name { font-weight: 600; font-size: 14px; color: var(--text); }
.company-sub { font-size: 11px; color: var(--text-muted); }

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-box svg { position: absolute; left: 12px; color: var(--text-muted); pointer-events: none; }
.search-box input { padding-left: 38px; background: var(--bg); border-color: transparent; }

.icon-btn {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition);
    position: relative;
}
.icon-btn:hover { background: var(--primary-lighter); color: var(--primary); }
.badge-dot {
    position: absolute; top: 8px; right: 9px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--danger); border: 2px solid var(--surface);
}

.period-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-size: 13px; font-weight: 600;
    transition: all var(--transition);
}
.period-badge:hover { background: var(--primary); color: #fff; }

.user-menu {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    position: relative;
    transition: background var(--transition);
}
.user-menu:hover { background: var(--primary-lighter); }
.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 16px;
    text-transform: uppercase;
}
.user-info { line-height: 1.2; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

.dropdown {
    position: absolute;
    top: calc(100% + 6px); right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    padding: 6px;
    display: none;
    z-index: 200;
}
.dropdown.show { display: block; }
.dropdown a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
}
.dropdown a:hover { background: var(--primary-lighter); color: var(--primary); }
.dropdown a svg { color: var(--text-muted); }

#menuBtn { display: none; }

/* CONTENT */
.content {
    flex: 1;
    padding: 20px;
    max-width: 100%;
    overflow-x: hidden;
}
.app-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}
.app-footer-meta { display:flex; flex-wrap:wrap; gap:6px 14px; justify-content:center; align-items:center; margin-bottom:6px; }
.app-footer-meta > span:first-child { font-weight:700; }
.app-footer-dot { display:none; }
.app-footer-update { color:var(--primary); font-weight:700; text-decoration:none; }
.app-footer-update:hover { text-decoration:underline; }
.app-footer-contacts { display:flex; flex-wrap:wrap; gap:6px 12px; justify-content:center; align-items:center; }
.footer-contact { display:inline-flex; align-items:center; gap:4px; padding:0; color:var(--text-muted); font:inherit; text-decoration:none; cursor:pointer; }
.footer-contact:hover { color:var(--primary); text-decoration:underline; }
.footer-contact:first-child { color:var(--primary); font-weight:700; }
.footer-icon { font-size:14px; line-height:1; }
.app-footer-copyright { margin-top:6px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
    .topbar-center { max-width: 280px; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.show { transform: translateX(0); }
    .sidebar-toggle { display: flex; }
    .main { margin-left: 0; }
    .sidebar-overlay.show { display: block; }
    #menuBtn { display: flex; }
    .topbar-center { display: none; }
}

@media (max-width: 640px) {
    .content { padding: 12px; }
    .app-footer { padding:14px 12px; }
    .topbar { padding: 0 12px; gap: 8px; }
    .company-info { display: none; }
    .user-info { display: none; }
    .period-badge { padding: 6px 10px; font-size: 12px; }
    .topbar-left { gap: 8px; }
}
