/**
 * TP-ERP Main Stylesheet
 * Version: 1.0.0
 */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --dark: #1e293b;
    --light: #f8fafc;
    --white: #ffffff;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --header-height: 60px;
}

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

body {
    font-family: 'Sarabun', 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--dark);
    background: #f1f5f9;
}

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

a:hover {
    text-decoration: underline;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: var(--white);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    -webkit-overflow-scrolling: touch;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand {
    font-size: 24px;
    font-weight: 700;
    color: var(--white);
}

.sidebar-brand span {
    color: var(--primary);
}

.sidebar-menu {
    list-style: none;
    padding: 15px 0;
}

.sidebar-menu-header {
    padding: 10px 20px;
    font-size: 11px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.4);
    letter-spacing: 1px;
}

.sidebar-menu-item {
    margin: 2px 10px;
}

.sidebar-menu-item a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: rgba(255,255,255,0.8);
    border-radius: 8px;
    transition: all 0.2s;
    text-decoration: none;
}

.sidebar-menu-item a:hover,
.sidebar-menu-item a.active {
    background: rgba(255,255,255,0.1);
    color: var(--white);
}

.sidebar-menu-item a.active {
    background: var(--primary);
}

.sidebar-menu-item i {
    width: 24px;
    margin-right: 12px;
    font-size: 18px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
}

/* Header */
.header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-dropdown {
    position: relative;
}

.user-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--light);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.user-dropdown-toggle:hover {
    background: var(--border);
}

.user-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* Content Area */
.content {
    padding: 24px;
}

/* Sidebar toggle: hidden on desktop, visible on mobile via media query */
.sidebar-toggle {
    display: none;
}

/* ========== Components ========== */

/* Cards */
.card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 24px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--light);
    border-radius: 0 0 12px 12px;
}

/* Stat Cards */
.stat-card {
    display: flex;
    align-items: center;
    padding: 20px;
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-right: 16px;
}

.stat-icon.primary { background: rgba(37, 99, 235, 0.1); color: var(--primary); }
.stat-icon.success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-icon.warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.stat-icon.danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.stat-info h3 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
}

.stat-info p {
    color: var(--secondary);
    margin: 4px 0 0;
}

/* Grid */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: -12px;
}

.col { padding: 12px; }
.col-12 { width: 100%; }
.col-6 { width: 50%; }
.col-4 { width: 33.333%; }
.col-3 { width: 25%; }
.col-8 { width: 66.666%; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    gap: 8px;
}

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: var(--white); }
.btn-success { background: var(--success); color: var(--white); }
.btn-warning { background: var(--warning); color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--dark); }
.btn-outline:hover { background: var(--light); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-control.error {
    border-color: var(--danger);
}

.form-error {
    color: var(--danger);
    font-size: 12px;
    margin-top: 4px;
}

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='%2364748b'%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 12px center;
    background-size: 16px;
    padding-right: 40px;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--light);
    font-weight: 600;
    white-space: nowrap;
}

.table tbody tr:hover {
    background: var(--light);
}

.table .text-right {
    text-align: right;
}

.table .text-center {
    text-align: center;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-primary { background: rgba(37, 99, 235, 0.1); color: var(--primary); }
.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.badge-secondary { background: rgba(100, 116, 139, 0.1); color: var(--secondary); }

/* Alerts */
.alert {
    padding: 14px 18px;
    border-radius: 8px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success { background: rgba(16, 185, 129, 0.1); color: #047857; border: 1px solid #a7f3d0; }
.alert-danger { background: rgba(239, 68, 68, 0.1); color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: rgba(245, 158, 11, 0.1); color: #b45309; border: 1px solid #fde68a; }
.alert-info { background: rgba(6, 182, 212, 0.1); color: #0e7490; border: 1px solid #a5f3fc; }

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.show {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--secondary);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Login Page styles moved to login.css */

/* ========== Dashboard ========== */
.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.chart-container {
    height: 300px;
}

/* ========== Utilities ========== */
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-secondary { color: var(--secondary); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-bold { font-weight: 600; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }
.nowrap { white-space: nowrap; }

/* ========== Responsive ========== */
@media (max-width: 1200px) {
    .dashboard-summary { grid-template-columns: repeat(2, 1fr); }
    .col-4 { width: 50%; }
    .col-3 { width: 50%; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }

    .header {
        padding: 0 12px;
    }

    .header-title {
        font-size: 16px;
    }

    .sidebar-toggle {
        display: inline-flex !important;
    }

    .user-dropdown-toggle span,
    .user-dropdown-toggle .ri-arrow-down-s-line {
        display: none;
    }

    .content {
        padding: 12px;
    }
    
    .dashboard-summary { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .col-6, .col-4, .col-3, .col-8 { width: 100%; }
    .row { margin: -6px; }
    .col { padding: 6px; }
}

@media (max-width: 374px) {
    .dashboard-summary { grid-template-columns: 1fr; }
}
