:root {
    /* Dark Theme - Purple & Night Blue Palette */
    --bg-dark: #0f1016;
    /* Deepest background */
    --bg-card: #181b26;
    /* Card/Panel background */
    --bg-input: #0f1016;
    /* Input fields */
    --sidebar-bg: #13151f;
    /* Sidebar background */

    --primary-color: #8b5cf6;
    /* Light Purple */
    --primary-dark: #7c3aed;
    /* Darker Purple */
    --accent-gradient: linear-gradient(135deg, #a78bfa 0%, #7c3aed 100%);
    --accent-glow: 0 0 20px rgba(124, 58, 237, 0.4);

    --text-main: #f1f5f9;
    /* White/Off-white */
    --text-muted: #94a3b8;
    /* Grey text */
    --border-color: #2e3546;
    /* Dark borders */

    --sidebar-width: 260px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --border-radius: 10px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    color: var(--text-main);
    position: fixed;
    height: 100%;
    left: 0;
    top: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Desktop sidebar collapse state */
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}

body.sidebar-collapsed .main-content {
    margin-left: 0;
}

.sidebar-header {
    padding: 30px 20px;
    display: grid;
    align-items: center;
    gap: 12px;
}

.sidebar h2 {
    text-align: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.5px;

}

.sidebar-header p {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* Sidebar Navigation */
.nav-links {
    list-style: none;
    padding: 0 16px;
    margin-top: 10px;
}

.nav-links li {
    margin-bottom: 8px;
}

.nav-links a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-links a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-links a.active {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: var(--accent-glow);
}

.nav-icon {
    margin-right: 12px;
    width: 20px;
    text-align: center;
}

/* Main Content Area */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 20px;
    transition: margin-left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: var(--bg-dark);
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-main);
    letter-spacing: 0.5px;
    margin-left: 50px;
}

.user-info {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
}

.card-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 16px;
    background: var(--accent-gradient);
    border-radius: 2px;
    margin-right: 10px;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.form-control {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.form-control::placeholder {
    color: rgba(148, 163, 184, 0.5);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--accent-glow);
}

.btn-secondary {
    background: #334155;
    color: #e2e8f0;
}

.btn-secondary:hover {
    background: #475569;
    box-shadow: none;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    text-transform: uppercase;
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }

    .sidebar,
    header,
    .no-print,
    .btn {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }

    .card {
        border: none;
        box-shadow: none;
        background: none;
        padding: 0;
    }

    .card-title {
        color: black;
    }

    table,
    th,
    td {
        border: 1px solid black;
        color: black;
    }
}

/* Utilities */
.text-right {
    text-align: right;
}

.mt-3 {
    margin-top: 1rem;
}

.d-none {
    display: none;
}

/* =========================================
   Login Page Styling
   ========================================= */
.login-page {
    background: radial-gradient(circle at top right, #2a2d3e 0%, var(--bg-dark) 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 800px;
    height: 800px;
    background: radial-gradient(circle, rgba(124, 58, 237, 0.15) 0%, rgba(124, 58, 237, 0) 70%);
    border-radius: 50%;
    z-index: 0;
}

.login-page::after {
    content: '';
    position: absolute;
    bottom: -20%;
    left: -10%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.1) 0%, rgba(56, 189, 248, 0) 70%);
    border-radius: 50%;
    z-index: 0;
}

.login-wrapper {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    z-index: 1;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: rgba(24, 27, 38, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: cardFadeIn 0.6s ease-out forwards;
}

@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-circle {
    width: 64px;
    height: 64px;
    background: var(--accent-gradient);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 0 30px rgba(124, 58, 237, 0.3);
    color: white;
    transform: rotate(-5deg);
    transition: transform 0.3s ease;
}

.login-card:hover .logo-circle {
    transform: rotate(0deg) scale(1.05);
}

.login-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    gap: 10px;
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.input-icon-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 16px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color 0.3s;
}

.form-control.with-icon {
    padding-left: 48px;
}

.form-control:focus+.input-icon,
.form-control:focus~.input-icon {
    /* Just in case structure varies slightly */
    color: var(--primary-color);
}

/* Fix CSS peer selection if needed based on DOM order */
.input-icon-wrapper:focus-within .input-icon {
    color: var(--primary-color);
}

.btn-block {
    width: 100%;
    margin-top: 24px;
    padding: 14px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 50px;
}

.btn-block svg {
    transition: transform 0.3s;
}

.btn-block:hover svg {
    transform: translateX(4px);
}

.login-footer {
    text-align: center;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.login-footer p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.login-footer .author {
    color: rgba(148, 163, 184, 0.6);
    font-size: 0.75rem;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.03);
}

.btn-icon:hover {
    transform: translateY(-2px);
}

.btn-edit {
    color: #60a5fa;
    /* Blue-400 */
    background: rgba(96, 165, 250, 0.1);
}

.btn-edit:hover {
    color: #3b82f6;
    /* Blue-500 */
    background: rgba(59, 130, 246, 0.2);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.btn-delete {
    color: #f87171;
    /* Red-400 */
    background: rgba(248, 113, 113, 0.1);
}

.btn-delete:hover {
    color: #ef4444;
    /* Red-500 */
    background: rgba(239, 68, 68, 0.2);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.2);
}

.table-responsive {
    overflow-x: auto;
}

/* =========================================
   Mobile Toggle Button & Overlay
   ========================================= */
.sidebar-toggle {
    display: flex;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1100;
    width: 44px;
    height: 44px;
    background: var(--accent-gradient);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    box-shadow: var(--accent-glow);
    transition: all 0.3s ease;
    align-items: center;
    justify-content: center;
}

/* On desktop, position toggle inside sidebar area when sidebar is visible */
@media screen and (min-width: 769px) {
    .sidebar-toggle {
        left: calc(var(--sidebar-width) + 16px);
        top: 16px;
        width: 40px;
        height: 40px;
        background: rgba(139, 92, 246, 0.2);
        box-shadow: none;
    }

    .sidebar-toggle:hover {
        background: var(--accent-gradient);
        box-shadow: var(--accent-glow);
    }

    body.sidebar-collapsed .sidebar-toggle {
        left: 16px;
        background: var(--accent-gradient);
        box-shadow: var(--accent-glow);
    }
}

.sidebar-toggle:hover {
    transform: scale(1.05);
}

.sidebar-toggle:active {
    transform: scale(0.95);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Sidebar Close Button - Only visible on mobile */
.sidebar-close {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.sidebar-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-main);
}

.sidebar-close:active {
    transform: scale(0.95);
}

@media screen and (max-width: 768px) {
    .sidebar-close {
        display: flex;
    }
}

/* =========================================
   Responsive Breakpoints
   ========================================= */

/* Tablet (768px - 1024px) */
@media screen and (max-width: 1024px) {
    :root {
        --sidebar-width: 240px;
    }

    .main-content {
        padding: 24px;
    }

    .form-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 16px;
    }

    header h1 {
        font-size: 1.3rem;
    }
}

/* Mobile (below 768px) */
@media screen and (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    /* Show toggle button */
    .sidebar-toggle {
        display: flex;
    }

    /* Sidebar off-canvas */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.5);
    }

    /* Main content full width */
    .main-content {
        margin-left: 0;
        padding: 80px 16px 24px 16px;
        width: 100%;
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }

    /* Header adjustments */
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }

    header h1 {
        font-size: 1.2rem;
        padding-right: 50px;
    }

    .user-info {
        font-size: 0.85rem;
    }

    /* Cards */
    .card {
        padding: 16px;
        margin-bottom: 16px;
        border-radius: 10px;
    }

    .card-header {
        margin-bottom: 16px;
        padding-bottom: 12px;
    }

    .card-title {
        font-size: 1rem;
    }

    /* Form adjustments */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .form-group {
        margin-bottom: 14px;
    }

    .form-control {
        padding: 14px 16px;
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    /* Buttons */
    .btn {
        padding: 14px 20px;
        font-size: 0.9rem;
        width: 100%;
        margin-bottom: 10px;
    }

    .mt-3.text-right {
        text-align: center;
    }

    /* Tables */
    th,
    td {
        padding: 10px 8px;
        font-size: 0.85rem;
    }

    th {
        font-size: 0.75rem;
    }

    /* Result section */
    #resultSection .flex {
        flex-direction: column;
    }

    /* Sidebar header on mobile */
    .sidebar-header {
        padding: 24px 16px;
        position: relative;
    }

    .sidebar h2 {
        font-size: 1.1rem;
    }

    .nav-links {
        padding: 0 12px;
    }

    .nav-links a {
        padding: 14px;
        font-size: 0.9rem;
    }

    /* Grand total responsive */
    .grand-total {
        font-size: 1.1rem;
        padding: 16px;
    }
}

/* Small mobile (below 480px) */
@media screen and (max-width: 480px) {
    .main-content {
        padding: 70px 12px 20px 12px;
    }

    .card {
        padding: 14px;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .form-control {
        padding: 12px 14px;
    }

    th,
    td {
        padding: 8px 6px;
        font-size: 0.8rem;
    }

    /* Stack rekap cards */
    div[style*="display:flex"][style*="flex-wrap:wrap"] {
        flex-direction: column !important;
    }

    div[style*="display:flex"][style*="flex-wrap:wrap"]>div {
        flex: none !important;
        width: 100% !important;
    }
}

/* Landscape mobile */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        width: 70%;
        max-width: 300px;
    }

    .main-content {
        padding-top: 70px;
    }
}

/* Touch-friendly improvements for mobile */
@media (hover: none) and (pointer: coarse) {
    .btn:active {
        transform: scale(0.98);
    }

    .nav-links a:active {
        background-color: rgba(255, 255, 255, 0.1);
    }

    /* Larger touch targets */
    .sidebar-toggle {
        width: 48px;
        height: 48px;
    }

    .form-control {
        min-height: 48px;
    }

    select.form-control {
        min-height: 48px;
    }
}