/**
 * style.css
 * Pengganti: tema visual Delphi VCL 
 * Color base: $F2F2F2 (dari MasterForm.FormCreate)
 */

:root {
    --primary: #0d9488;
    --primary-dark: #0f766e;
    --primary-light: #ccfbf1;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0891b2;
    --bg-body: #f0f4f8;
    --bg-white: #ffffff;
    --bg-card: #ffffff;
    --card-bg: #ffffff;
    --border: #d1d5db;
    --border-light: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --radius: 6px;
    --radius-lg: 10px;
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Consolas', 'Courier New', monospace;
    --header-height: 52px;
    --sidebar-width: 220px;
    --sidebar-collapsed: 56px;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-hover: #1e293b;
    --sidebar-active-bg: rgba(13,148,136,0.15);
    --sidebar-active-text: #5eead4;
    --sidebar-section-text: #475569;
}

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

html { font-size: 14px; }

body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ============ LOGIN PAGE ============ */

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #0d9488 50%, #0f766e 100%);
    padding: 1rem;
}

.login-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
}

.login-header {
    background: linear-gradient(135deg, #0f172a 0%, #0f766e 100%);
    padding: 2rem 2rem 1.5rem;
    text-align: center;
    color: #fff;
}

.login-header img {
    max-height: 56px;
    margin-bottom: 0.75rem;
}

.login-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.login-header p {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 0.25rem;
}

.login-body {
    padding: 2rem;
}

.login-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    display: none;
}

.login-error.show { display: block; }

/* ============ FORM CONTROLS ============ */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-control {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-size: 0.95rem;
    font-family: var(--font);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-white);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

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

.form-control:disabled {
    background: #f3f4f6;
    color: var(--text-muted);
    cursor: not-allowed;
}

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

.form-control-sm {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 70px;
}

/* ============ BUTTONS ============ */
/* Pengganti: TABButton di MasterForm */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-family: var(--font);
    font-weight: 500;
    border: 1.5px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-warning {
    background: var(--warning);
    color: #fff;
    border-color: var(--warning);
}

.btn-secondary {
    background: #6b7280;
    color: #fff;
    border-color: #6b7280;
}
.btn-secondary:hover:not(:disabled) { background: #4b5563; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
    background: var(--primary-light);
    border-color: var(--primary);
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.65rem 1.5rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ============ LAYOUT - APP SHELL ============ */
/* Pengganti: MainForm MDI layout */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--border-light);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    z-index: 100;
}

.app-header .logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--primary-dark);
    width: var(--sidebar-width);
    flex-shrink: 0;
    transition: width 0.15s ease;
}
.app-header .logo img { height: 26px; width: auto; max-width: 36px; flex-shrink: 0; object-fit: contain; }
.app-header .logo .logo-text { white-space: nowrap; overflow: hidden; }

.sidebar-toggle {
    background: none; border: none; cursor: pointer; color: var(--text-secondary);
    width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center;
    justify-content: center; transition: background 0.15s; flex-shrink: 0;
}
.sidebar-toggle:hover { background: #f1f5f9; }

.app-header .header-title {
    flex: 1;
    font-size: 0.88rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.app-header .header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.app-header .header-user .user-name {
    font-weight: 600;
    color: var(--text-primary);
}

/* ============ SIDEBAR ============ */

.app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: none;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    z-index: 90;
    transition: width 0.15s ease;
    scrollbar-width: thin;

/* Sidebar logo area */
.sidebar-logo-area {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #1e293b;
    height: 48px; overflow: hidden; flex-shrink: 0;
}
.sb-logo-img { height: 24px; width: auto; max-width: 32px; flex-shrink: 0; object-fit: contain; }
.sb-logo-text { font-size: 0.72rem; font-weight: 700; color: #e2e8f0; letter-spacing: 1px; white-space: nowrap; overflow: hidden; }

.sidebar-section {
    padding: 0.15rem 0;
}

.sidebar-section-title {
    padding: 0.45rem 0.9rem 0.15rem;
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sidebar-section-text);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.38rem 0.9rem;
    font-size: 0.78rem;
    color: var(--sidebar-text);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.12s;
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-item:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}

.sidebar-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    border-left-color: var(--primary);
}

.sidebar-item svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    opacity: 0.7;
}
.sidebar-item:hover svg, .sidebar-item.active svg { opacity: 1; }

.sb-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tooltip on collapsed hover — fixed position, vertical via JS --tip-top */
.sb-collapsed .sidebar-item { position: relative; --tip-top: 0px; }
.sb-collapsed .sidebar-item:hover::after {
    content: attr(title);
    position: fixed;
    left: calc(var(--sidebar-collapsed) + 8px);
    top: var(--tip-top);
    background: #1e293b;
    color: #f1f5f9;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.74rem;
    font-weight: 500;
    white-space: nowrap;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0,0,0,0.35);
    pointer-events: none;
}
.sb-collapsed .sidebar-item:hover::before {
    content: '';
    position: fixed;
    left: calc(var(--sidebar-collapsed) + 3px);
    top: calc(var(--tip-top) + 4px);
    border: 5px solid transparent;
    border-right-color: #1e293b;
    z-index: 9999;
    pointer-events: none;
}
/* Section title tooltip */
.sb-collapsed .sidebar-section-title { position: relative; cursor: default; --tip-top: 0px; }
.sb-collapsed .sidebar-section-title:hover::after {
    content: attr(data-title);
    position: fixed;
    left: calc(var(--sidebar-collapsed) + 8px);
    top: var(--tip-top);
    background: #0f766e;
    color: #fff;
    padding: 3px 10px;
    border-radius: 5px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
    z-index: 9999;
    pointer-events: none;
}
}

/* ============ MAIN CONTENT ============ */

.app-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    padding: 1rem;
    min-height: calc(100vh - var(--header-height));
    overflow-x: hidden;
    transition: margin-left 0.15s ease;
}

/* ============ PAGE HEADER ============ */
/* Pengganti: MasterForm.PHead (panel header dgn bg2Text + frontText) */

.page-header {
    background: linear-gradient(135deg, #0f766e 0%, #0d9488 50%, #14b8a6 100%);
    color: #fff;
    padding: 0.8rem 1.25rem;
    border-radius: var(--radius-lg);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.page-header .page-actions {
    display: flex;
    gap: 0.4rem;
}

.page-header .btn {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-color: rgba(255,255,255,0.25);
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
}

.page-header .btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ============ CARD ============ */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.card-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1rem;
}

.card-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-light);
    background: #f9fafb;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============ ACTION BAR ============ */
/* Pengganti: ActionList di MasterForm (Simpan, Ubah, Hapus, Batal, Keluar) */

.action-bar {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #f9fafb;
    border-top: 1px solid var(--border-light);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    flex-wrap: wrap;
}

.action-bar .btn svg { width: 16px; height: 16px; }

/* ============ DATA TABLE ============ */
/* Pengganti: cxGrid / DBGrid */

.data-table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table thead th {
    background: #f3f4f6;
    padding: 0.55rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

.data-table tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.data-table tbody tr.selected {
    background: var(--primary-light);
}

.data-table tbody tr { cursor: pointer; }

.data-table .col-num { text-align: right; font-family: var(--font-mono); }
.data-table .col-center { text-align: center; }
.data-table .col-action { text-align: center; white-space: nowrap; }

/* ============ FORM GRID ============ */

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Label-input pair (pengganti ABEditLabel yang ada label+input jadi satu) */
.field-pair {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.field-pair label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.field-pair .required::after {
    content: ' *';
    color: var(--danger);
}

/* ============ MODAL ============ */
/* Pengganti: Form.ShowModal di Delphi */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

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

.modal-box {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    background: #f9fafb;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0.2rem;
}

.modal-close:hover { color: var(--text-primary); }

/* ============ TABS ============ */
/* Pengganti: TPageControl / TTabControl */

.tab-bar {
    display: flex;
    border-bottom: 2px solid var(--border-light);
    margin-bottom: 1rem;
    gap: 0;
}

.tab-item {
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: var(--font);
}

.tab-item:hover { color: var(--primary); }
.tab-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============ ALERTS / PESAN ============ */
/* Pengganti: MessageError(), MessageInfo(), PesanSimpan(), dll di MasterForm.pas */

.alert {
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    border: 1px solid transparent;
}

.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #ecfeff; border-color: #a5f3fc; color: #155e75; }

/* ============ TOAST NOTIFICATION ============ */

.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 0.75rem);
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 280px;
    border-left: 4px solid var(--primary);
    animation: toastIn 0.25s ease;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ============ BADGES ============ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 9999px;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fef2f2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* ============ LOADING ============ */

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    border-radius: var(--radius-lg);
}

/* ============ PAGINATION ============ */

.pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
}

.pagination .page-btn {
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.8rem;
}

.pagination .page-btn:hover { background: #f3f4f6; }
.pagination .page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ============ RESPONSIVE ============ */

@media (max-width: 768px) {
    .app-sidebar { transform: translateX(-100%); transition: transform 0.25s ease, width 0.25s ease; width: 240px !important; }
    .app-sidebar.open { transform: translateX(0); }
    .app-content { margin-left: 0 !important; }
    .sb-collapsed .app-content { margin-left: 0 !important; }
    .app-header .logo { width: auto; }
    .hdr-hide-sm { display: none; }
    .form-row-2, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
    .modal-box { max-width: 100%; margin: 0.5rem; }
    .sidebar-toggle { display: flex; }
}
@media (min-width: 769px) {
    .app-sidebar.open { transform: none; }
}

/* ============ UTILITY ============ */

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-small { font-size: 0.78rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.d-flex { display: flex; }
.d-none { display: none; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
