/* ==========================================
   Common Styles - Based on CLAUDE.md Design Spec
   ========================================== */

/* Google Fonts: Inter + Noto Sans SC */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Serif+SC:wght@500;700&family=Noto+Sans+SC:wght@400;500;700&display=swap');

/* ==========================================
   CSS Variables
   ========================================== */
:root {
    /* Fonts */
    --font-primary: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Noto Serif SC', serif;

    /* Colors - Warm paper palette */
    --bg-primary: #f5f1eb;
    --bg-card: #ffffff;
    --bg-warm: #faf4e6;
    --text-primary: #1c1917;
    --text-secondary: #78716c;
    --text-muted: #a8a29e;
    --accent-primary: #b45309;
    --accent-hover: #92400e;
    --accent-secondary: #15803d;
    --accent-warm: #dc2626;
    --accent-warn: #d97706;
    --border-subtle: #e7e5e4;
    --border-medium: #d6d3d1;

    /* Shadows */
    --shadow-card: 0 1px 3px rgba(28,25,23,0.04), 0 4px 12px rgba(28,25,23,0.06);
    --shadow-elevated: 0 4px 6px rgba(28,25,23,0.03), 0 10px 24px rgba(28,25,23,0.08);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ==========================================
   Base Styles
   ========================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-primary);
    background-color: var(--bg-primary);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

/* ==========================================
   Button Styles
   ========================================== */
.btn {
    background: transparent;
    border: 1px solid var(--border-medium);
    padding: 8px 16px;
    font-size: 14px;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: var(--font-primary);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(180, 83, 9, 0.25);
}

.btn-primary:active {
    transform: scale(0.97) translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-success {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
    color: white;
}

.btn-success:hover {
    background: #166534;
    border-color: #166534;
    color: white;
}

.btn-danger {
    background: var(--accent-warm);
    border-color: var(--accent-warm);
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* ==========================================
   Form Styles
   ========================================== */
.form-group {
    margin-bottom: 24px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 12px 0;
    min-height: 44px;
    border: none;
    border-bottom: 2px solid var(--border-subtle);
    font-size: 15px;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-primary);
    transition: border-color var(--transition-normal);
}

.form-input:focus {
    outline: none;
    border-bottom-color: var(--accent-primary);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-select {
    width: 100%;
    padding: 12px 0;
    min-height: 44px;
    border: none;
    border-bottom: 2px solid var(--border-subtle);
    font-size: 15px;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-primary);
    cursor: pointer;
    transition: border-color var(--transition-normal);
}

.form-select:focus {
    outline: none;
    border-bottom-color: var(--accent-primary);
}

.form-row {
    margin-bottom: 20px;
}

.form-row label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.form-row input,
.form-row select,
.form-row textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-primary);
    transition: border-color var(--transition-normal);
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Password input wrapper */
.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper input {
    flex: 1;
    padding-right: 44px;
}

.password-toggle {
    position: absolute;
    right: 0;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}

.password-toggle:hover {
    color: var(--text-secondary);
}

/* ==========================================
   Card Styles
   ========================================== */
.card {
    background: var(--bg-card);
    padding: 24px;
    box-shadow: var(--shadow-card);
    position: relative;
    transition: all var(--transition-normal);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated);
}

.card-header {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.card-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.card-value {
    font-family: var(--font-serif);
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 8px 0;
}

.card-footer {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ==========================================
   Section Styles
   ========================================== */
.section {
    background: var(--bg-card);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
    position: relative;
}

.section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent-primary);
    opacity: 0.8;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-title {
    font-family: var(--font-serif);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

/* ==========================================
   Toast Styles
   ========================================== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    z-index: 1000;
    display: none;
    animation: slideDown 0.3s ease-out;
}

.toast.show { display: block; }
.toast.success { background: var(--accent-secondary); }
.toast.error { background: var(--accent-warm); }

@keyframes slideDown {
    from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================
   Modal Styles
   ========================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(28, 25, 23, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-elevated);
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

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

.modal-body {
    padding: 24px;
}

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

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    transition: color var(--transition-fast);
}

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

/* ==========================================
   Table Styles
   ========================================== */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrapper::-webkit-scrollbar {
    height: 6px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: var(--bg-warm);
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

th {
    background: var(--bg-warm);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

tr:hover {
    background: var(--bg-warm);
}

/* ==========================================
   Empty State
   ========================================== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state div {
    font-size: 14px;
}

/* ==========================================
   Loading States
   ========================================== */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, var(--border-subtle) 25%, var(--bg-warm) 50%, var(--border-subtle) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 12px;
}

/* ==========================================
   Utility Classes
   ========================================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }

.hidden { display: none !important; }

/* ==========================================
   Responsive Breakpoints
   ========================================== */
@media (max-width: 768px) {
    .section { padding: 20px; }
    .card { padding: 20px; }
    .modal-content { max-width: 100%; }
}

@media (max-width: 480px) {
    .section { padding: 16px; }
    .card { padding: 16px; }
    .btn-primary { padding: 10px 20px; }
}
